UIImagePickerController的简单使用
2014-09-02 15:26
441 查看
#pragma mark 当点击修改头像按钮的时候,触发的方法 - (IBAction)modifyUserPic:(UIButton *)sender { myActionSheet = [[UIActionSheetalloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"打开相机",@"从相册中选择",nil]; [myActionSheet showInView:self.view]; } #pragma mark - UIActionSheetDelegate - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { switch (buttonIndex) { case 0: [self takePhoto];//打开相机 break; case 1: [self loadPhoto];//打开本地相册 break; } } //开始拍照 -(void)takePhoto { UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { UIImagePickerController *picker = [[UIImagePickerControlleralloc]init]; picker.delegate = self; picker.allowsEditing = YES; picker.sourceType = sourceType; [self presentViewController:picker animated:YEScompletion:nil]; } else { UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"无法打开相机,请在真机中调试!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; } } //打开本地相册 -(void)loadPhoto { UIImagePickerController *picker = [[UIImagePickerControlleralloc]init]; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; picker.delegate = self; picker.allowsEditing = YES; [selfpresentViewController:picker animated:YES completion:^{}]; } #pragma mark - UIImagePickerControllerDelegate - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { _userPicImageView.image = [info objectForKey:UIImagePickerControllerEditedImage]; [picker dismissViewControllerAnimated:YES completion:nil]; }
相关文章推荐
- UIImagePickerController简单使用
- UIImagePickerController简单使用
- IOS开发之小实例--使用UIImagePickerController创建一个简单的相机应用程序
- 关于UIImagePickerController的简单使用
- UIImagePickerController简单使用
- ios中UIImagePickerController 图片选取器的使用
- 使用UIImagePickerController拍照或者视频选择问题
- IOS 摄像头使用 之UIImagePickerController
- iphone 怎么使用图片选取器 UIImagePickerController
- 使用UIImagePickerController拍照或者视频选择问题
- iphone 怎么使用图片选取器 UIImagePickerController
- iphone:使用UIImagePickerController从IPhone照片库或照相机获取图像
- UIImagePickerController使用方法
- 不使用UIImagePickerController实现读取相册图片的方法
- IOS7-UIImagePickerController使用
- iOS之摄像头的使用-----UIImagePickerController
- ios 使用UIImagePickerController 打开图片库和相机选择图片修改头像(iphone版本)
- Monotouch在IPAD与IPhone使用UIImagePickerController的图片选择不同的代码
- 使用线程加载UIImagePickerController,解决卡屏问题
- IOS 摄像头使用(1)-UIImagePickerController