通过UIImagePickerController完成照相和相片的选取
UIImagePickerController是用于选取现有照片,或者用照相机现场照一张相片使用的
定义:
@interface ShowViewController : UIViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
UIImagePickerController * imagePicker;
这里需要注意,Delegate可以不写,但是不写会有警告发生,所以还是写上比较好
使用:
imagePicker = [[UIImagePickerControlleralloc]init];
UIImagePickerControllerSourceTypesoureType;
//soureType当改成UIImagePickerControllerSourceTypeCamera时为照相机照照片模式,UIImagePickerControllerSourceTypePhotoLibrary为相册选取模式
soureType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate =self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = soureType;
UIDevice *device = [UIDevice currentDevice];
NSLog(@"device.model %@",device.model);
[selfpresentViewController:imagePickeranimated:YEScompletion:^(void){
}];
现在我使用的总共是两种模式,两种模式的切换全都在SoureType里面
最后一句presentViewController用的是切换视图,把当前视图切换到选取照片的视图或者拍照片的视图。
必须实现的接口方法:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
inputImage = [info objectForKey:UIImagePickerControllerEditedImage];
[picker dismissViewControllerAnimated:YEScompletion:^(void){
}];
[appDelegatesetInputImage:inputImage];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YEScompletion:^(void){
}];
}
第一个方法是在选取照片以后,对照片的存储。通过info找到照片,并放到需要的地方。然后一句话是退出当前视图dismissViewController
第二个方法是取消照片选取以后的方法,这里我不需要进行任何动作,只需要退出当前视图就够了
最新文章
- datatables中的Options总结(2)
- .htaccess 的写法
- Unity 坐标系
- IOS NSThread
- 小而美的js程序
- Xcode中的几个常用文件路径
- 【Siverlight - 扩展篇】Silverlight在OOB模式下实现默认打开最大化
- 30.SSH配置文件模板.md
- MEAN全栈开发实践
- ios控件 UIImageView
- IIS易混概念小结
- maven入门(7)maven项目(组件)的坐标
- 第五节: EF高级属性(一) 之 本地缓存、立即加载、延迟加载(不含导航属性)
- 使用node去爬虫
- Android中使用Log4j及配置说明
- 31. The New Bread Earners 挣钱养家的新军
- cross-compler toolchains--clfs
- 从HiveQL到MapReduce job过程简析
- dubbo获取错误ip
- 给tomcat7w.exe改名字