SKFCameraiOS 的自定义相机

联合创作 · 2023-09-26 02:45

开发iOS应用的过程中,很多情景都要调用相机,大多数初学开发者都是采用的苹果提供的系统相机的方法。


   UIImagePickerController *imagePickerController =  [[UIImagePickerController alloc] init];
   imagePickerController.delegate = self;
   imagePickerController.allowsEditing = YES;
   imagePickerController.sourceType = sourceType;
   [self presentViewController:imagePickerController animated:YES completion:^{}];


头文件要遵守协议方法,


       <UIImagePickerControllerDelegate, UINavigationControllerDelegate>


然后在下这个代理方法了里面获取拍照以后的照片。


//该代理方法仅适用于只选取图片时


   - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(nullable NSDictionary<NSString *,id> *)editingInfo
     { NSLog(@"选择完毕----image:%@-----info:%@",image,editingInfo);
    }


使用非常的不方便,而且调用系统的相机是不能自定义相机页面的,且如果从一个横屏页面进入系统的相机,就会崩溃报错。


因为在做一个自定义相机页面的时候,遇到了上面所说的坑,所以就有了下面这个demo,我写的这个相机,采用frame布局,可以随意自定义拍照页面,支持横屏,自定义裁剪。


git地址https://github.com/wubianxiaoxian/SKFCamera


调用方法简单,首先下载demo,将SKFCamera添加到工程,引入


#import "SKFCamera.h"


然后五行代码就可以引用这个相机了


  SKFCamera *homec=[[SKFCamera alloc]init];
  __weak typeof(self)myself=self;
  homec.fininshcapture=^(UIImage *ss){
    if (ss) {
        NSLog(@"照片存在");
      //在这里获取裁剪后的照片
        myself.ViewImageview.image=ss;
    }
} ;
    [self presentViewController:homec animated:NO completion:^{}];}


运行效果:


浏览 14
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报