通过UIImagePickerController完成照相和相片的选取
2013-10-30 09:17
239 查看
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
第二个方法是取消照片选取以后的方法,这里我不需要进行任何动作,只需要退出当前视图就够了
定义:
@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
第二个方法是取消照片选取以后的方法,这里我不需要进行任何动作,只需要退出当前视图就够了
相关文章推荐
- mac上的键盘生活——quicksliver
- mac上的键盘生活——quicksliver
- 【Android UI】使用RelativeLayout与TableLayout实现登录界面
- 【Android UI】使用RelativeLayout与TableLayout实现登录界面
- DriverStudio 和 WDF驱动 通过GUID获取设备句柄的差别
- DriverStudio 和 WDF驱动 通过GUID获取设备句柄的差别
- NGUI 动态改变Label字体
- DriverStudio 和 WDF驱动 通过GUID获取设备句柄的差别
- DriverStudio 和 WDF驱动 通过GUID获取设备句柄的差别 分类: windows驱动程序WDM 2013-10-30 08:56 812人阅读 评论(0) 收藏
- C# GUID 知识点
- UITableViewCell和UITableView的学习
- Query操作option的添加、删除、取值
- WTL for MFC Programmers, Part V - Advanced Dialog UI Classes
- Indent Guides
- Ext中关于Ext.QuickTips.init()的使用
- Building FFplay for Windows
- iOS UIControl 几个事件的说明
- 各种UIButton
- 条件变量:BlockingQueue+CountDownLatch
- ant build 文件自动创建之方法