iOS中调用相机以及相册
来源:互联网 发布:arm编程 编辑:程序博客网 时间:2024/06/05 17:13
有时候需要在程序中调用系统的相机以及手机相册,接下来简要介绍调用的方法:
//.h文件
@interface CameraViewController : UIViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate>@property (nonatomic,retain)UIImageView *imageView;//@property (nonatomic,retain)UIImagePickerController *imageController;//图片控制器@end
</pre><p></p><p>这个时候可以给UIImageView进行初始化,然后初始化两个Button,分别是调用相机和调用相册</p><p></p><p></p><pre name="code" class="objc"> self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 64, 200, 200)]; _imageView.backgroundColor = [UIColor grayColor]; [self.view addSubview:_imageView];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem]; button1.frame = CGRectMake(20, 400, 80, 50); [button1 setTitle:@"照相机" forState:UIControlStateNormal]; [button1 addTarget:self action:@selector(enterCramera:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button1]; UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem]; button2.frame = CGRectMake(150, 400, 100, 50); [button2 setTitle:@"图库" forState:UIControlStateNormal]; [button2 addTarget:self action:@selector(enterPhotos:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button2];
实现两个Button的方法
//打开相机- (void)enterCramera:(UIButton*)button{ //如果设备里面没有相机 if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { //创建一个图片选择器 self.imageController = [[UIImagePickerController alloc] init]; self.imageView = UIImagePickerControllerSourceTypePhotoLibrary; _imageController.delegate = self; _imageController.allowsEditing = NO; [self presentViewController:_imageController animated:YES completion:nil]; }else{ UIAlertView *alertV = [[UIAlertView alloc] initWithTitle:@"提示" message:@"该设备不支持相机功能" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; //[self.view addSubview:alertV]; [alertV show]; } }
//打开相册- (void)enterPhotos:(UIButton*)button{ //创建一个图片选择器 self.imageController = [[UIImagePickerController alloc]init]; //指定图片来源 _imageController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;//从现有的照片库取照片 _imageController.delegate = self; _imageController.allowsEditing = YES;//设置为yes时,取出图片后会对图片进行放大或缩小以及移动位置 [self presentViewController:_imageController animated:YES completion:nil]; }
这时候就实现了对相机以及相册的调用;
imagePickControllerDelegate代理方法可以帮助我们实现更加丰富的功能
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo NS_DEPRECATED_IOS(2_0, 3_0);- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;
//UINavigationControllerDelegate代理方法
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 20px;">//当一个viewController要显示的时候通知一下外面,给我们一个机会进行设置,包含如下两个函数:</span>
<span style="font-family: Arial, Helvetica, sans-serif;">- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;</span>
<span style="font-family: Arial, Helvetica, sans-serif;">- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;</span>
<span style="font-family: Arial, Helvetica, sans-serif;">- (NSUInteger)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController NS_AVAILABLE_IOS(7_0);</span>
<span style="font-family: Arial, Helvetica, sans-serif;">- (UIInterfaceOrientation)navigationControllerPreferredInterfaceOrientationForPresentation:(UINavigationController *)navigationController NS_AVAILABLE_IOS(7_0);</span>
<span style="font-family: Arial, Helvetica, sans-serif;">- (id <UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController</span>
interactionControllerForAnimationController:(id <UIViewControllerAnimatedTransitioning>) animationController NS_AVAILABLE_IOS(7_0);
- (id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC NS_AVAILABLE_IOS(7_0);
0 0
- iOS中调用相机以及相册
- iOS 开发调用相机以及获取相册照片功能
- iOS 开发调用相机以及获取相册照片功能
- iOS调用相册、相机、上传
- iOS--调用相机和相册
- iOS 10调用相机相册
- android中调用相机、相册 以及图片压缩,文件压缩
- iOS中获取相册、相机、定位、以及麦克风权限设置
- iOS开发中调用系统相册、相机 显示中文标题
- ios中调用相机,相册,选择多张图片
- iOS中 读取相册,调用系统相机 技术分享
- iOS中 读取相册,调用系统相机 技术分享
- iOS中 iOS10 调用相机相册等权限崩溃问题
- Android 调用系统相机以及相册源码
- Android 调用系统相机以及相册源码
- iOS 相机权限以及相册权限访问
- ios调用相册或相机上传图片
- iOS调用相册、相机、上传等问题
- hadoop(hadoop-2.2.0) 安装
- [2014年中总结-暑假]TGB之旅
- poj_1195Mobile phones,二维树状数组
- 计算几何模板收藏。
- 深入理解C++的动态绑定和静态绑定
- iOS中调用相机以及相册
- java中static作用详解
- 一个界面实现多个listview
- MFC 和 数据库Access 用 Ado类 操作
- 从应用的角度了解遗传算法
- 机房收费 之 Excel导出
- Longest Substring Without Repeating Characters
- shell中流的重定向
- 可以用下面的方法让你的大脑就范