開發(fā)iOS應(yīng)用的過程中,很多情景都要調(diào)用相機(jī)梅掠,大多數(shù)初學(xué)開發(fā)者都是采用的蘋果提供的系統(tǒng)相機(jī)的方法藐鹤。
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.allowsEditing = YES;
imagePickerController.sourceType = sourceType;
[self presentViewController:imagePickerController animated:YES completion:^{}];
頭文件要遵守協(xié)議方法娱节,
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
然后在下這個代理方法了里面獲取拍照以后的照片。
//該代理方法僅適用于只選取圖片時
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(nullable NSDictionary<NSString *,id> *)editingInfo
{ NSLog(@"選擇完畢----image:%@-----info:%@",image,editingInfo);
}
使用非常的不方便肄满,而且調(diào)用系統(tǒng)的相機(jī)是不能自定義相機(jī)頁面的质涛,且如果從一個橫屏頁面進(jìn)入系統(tǒng)的相機(jī)汇陆,就會崩潰報錯带饱。
因?yàn)樵谧鲆粋€自定義相機(jī)頁面的時候,遇到了上面所說的坑勺疼,所以就有了下面這個demo,我寫的這個相機(jī),采用frame布局酪耕,可以隨意自定義拍照頁面轨淌,支持橫屏,自定義裁剪盟步。
git地址https://github.com/wubianxiaoxian/SKFCamera
使用方法
在info.plist 里面添加
Privacy - Microphone Usage Description 使用麥克風(fēng)
Privacy - Camera Usage Description 使用相機(jī)
-
Installation with CocoaPods:pod 'SKFCamera'梳虽,引入
#import <SKFCamera.h>
-
或者下載demo到本地將SKFCamera添加到工程,引入
#import "SKFCamera.h"
按照下面的方法引用相機(jī)
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:^{}];}