前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >iOS8新特性扩展(Extension)应用之三——照片编辑插件

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

作者头像
珲少
发布2018-08-16 11:05:41
3350
发布2018-08-16 11:05:41
举报
文章被收录于专栏:一“技”之长一“技”之长

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

        通过前几篇博客的介绍,我们了解到扩展给app提供的更加强大的交互能力,这种强大的交互能力另一方面体现在照片编辑插件的应用。

       和通常一样,我们先创建一个工程,然后新建一个Target,选择photo editing:

从模板中,我们可以看到系统为我们创建了一个controller,这个controller就是用于处理照片的controller,其中方法如下:

代码语言:javascript
复制
- (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类型的对象,这个对象专门用于负责版本的记录,这个对象中有如下两个属性用于区分版本:

@property (readonly, copy) NSString *formatIdentifier;

@property (readonly, copy) NSString *formatVersion;

专注技术,热爱生活,交流技术,也做朋友。 ——珲少 QQ群:203317592

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2015/07/30 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • iOS8新特性扩展(Extension)应用之三——照片编辑插件
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档