iOS8新特性扩展(Extension)应用之三——照片编辑插件

 iOS8新特性扩展(Extension)应用之三——照片编辑插件

        经过前几篇博客的介绍,咱们了解到扩展给app提供的更增强大的交互能力,这种强大的交互能力另外一方面体如今照片编辑插件的应用。app

       和一般同样,咱们先建立一个工程,而后新建一个Target,选择photo editing:async

从模板中,咱们能够看到系统为咱们建立了一个controller,这个controller就是用于处理照片的controller,其中方法以下:ide

- (BOOL)canHandleAdjustmentData:(PHAdjustmentData *)adjustmentData {
    // Inspect the adjustmentData to determine whether your extension can work with past edits.
    // (Typically, you use its formatIdentifier and formatVersion properties to do this.)
    return NO;
}
//这个函数用于从系统相册获取到选中的照片,contentEditingInput对象中存有响应的数据类型和image对象
- (void)startContentEditingWithInput:(PHContentEditingInput *)contentEditingInput placeholderImage:(UIImage *)placeholderImage {
   //咱们能够在这里将取到的数据进行展现等等
    self.input = contentEditingInput;
}
//结束编辑照片时的方法
- (void)finishContentEditingWithCompletionHandler:(void (^)(PHContentEditingOutput *))completionHandler {
    // Update UI to reflect that editing has finished and output is being rendered.
    
    // Render and provide output on a background queue.
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // Create editing output from the editing input.
        PHContentEditingOutput *output = [[PHContentEditingOutput alloc] initWithContentEditingInput:self.input];
        
        //咱们能够在这里将新的图片数据写入到输出流中
        // output.adjustmentData = <#new adjustment data#>;
        // NSData *renderedJPEGData = <#output JPEG#>;
        // [renderedJPEGData writeToURL:output.renderedContentURL atomically:YES];
        
        // Call completion handler to commit edit to Photos.
        completionHandler(output);
        
        // Clean up temporary files, etc.
    });
}

在当前扩展执行结束编辑以前,咱们能够自由渲染咱们获得的图片,例如添加相框,文字等等,输出时将渲染后的图片进行输出便可。函数

这里还有一个地方须要咱们注意,此类扩展有一个功能,若是咱们中途退出编辑,系统会为咱们保存咱们扩展的处理状态,为了区分多个相似功能的扩展,在输出数据的对象中有一个PHAdjustmentData类型的对象,这个对象专门用于负责版本的记录,这个对象中有以下两个属性用于区分版本:this

 

@property (readonly, copy) NSString *formatIdentifier;atom

@property (readonly, copy) NSString *formatVersion;spa


 

专一技术,热爱生活,交流技术,也作朋友。.net

——珲少 QQ群:203317592插件

相关文章
相关标签/搜索