码迷,mamicode.com
首页 > 移动开发 > 详细

iOS----------调用系统照相机和相册

时间:2018-01-12 19:43:29      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:nslog   lis   lib   cti   gpo   void   image   cancel   rar   

iOS 10 以后记得在plist里面添加获取拍照和相册权限,iOS 10 以后记得在plist里面添加获取拍照和相册权限,iOS 10 以后记得在plist里面添加获取拍照和相册权限,iOS 10 以后记得在plist里面添加获取拍照和相册权限,iOS 10 以后记得在plist里面添加获取拍照和相册权限,iOS 10 以后记得在plist里面添加获取拍照和相册权限,iOS 10 以后记得在plist里面添加获取拍照和相册权限,iOS 10 以后记得在plist里面添加获取拍照和相册权限,iOS 10 以后记得在plist里面添加获取拍照和相册权限,iOS 10 以后记得在plist里面添加获取拍照和相册权限,iOS 10 以后记得在plist里面添加获取拍照和相册权限,iOS 10 以后记得在plist里面添加获取拍照和相册权限,iOS 10 以后记得在plist里面添加获取拍照和相册权限,iOS 10 以后记得在plist里面添加获取拍照和相册权限。

 

/**

 *  调用照相机

 */

- (void)openCamera

{

    UIImagePickerController *picker = [[UIImagePickerController allocinit];

    picker.delegate = self;

    picker.allowsEditing = YES//可编辑

    //判断是否可以打开照相机

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])

    {

        //摄像头

        picker.sourceType = UIImagePickerControllerSourceTypeCamera;

        [self presentViewController:picker animated:YES completion:nil];

    }

    else

    {

        NSLog(@"没有摄像头");

    }

}

 

 

/**

 *  打开相册

 */

-(void)openPhotoLibrary

{

    // Supported orientations has no common orientation with the application, and [PUUIAlbumListViewController shouldAutorotate] is returning YES

    

    // 进入相册

    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])

    {

        UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];

        imagePicker.allowsEditing = YES;

        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        imagePicker.delegate = self;

        [self presentViewController:imagePicker animated:YES completion:^{

            NSLog(@"打开相册");

        }];

    }

    else

    {

        NSLog(@"不能打开相册");

    }

}

 

#pragma mark - UIImagePickerControllerDelegate

// 拍照完成回调

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(nullable NSDictionary<NSString *,id> *)editingInfo NS_DEPRECATED_IOS(2_0, 3_0)

{

    NSLog(@"finish..");

    

    if(picker.sourceType == UIImagePickerControllerSourceTypeCamera)

    {

        //图片存入相册

        UIImageWriteToSavedPhotosAlbum(image, nilnilnil);

    }

    

    [self dismissViewControllerAnimated:YES completion:nil];

}

//进入拍摄页面点击取消按钮

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

{

    [self dismissViewControllerAnimated:YES completion:nil];

}

 

 

iOS----------调用系统照相机和相册

标签:nslog   lis   lib   cti   gpo   void   image   cancel   rar   

原文地址:https://www.cnblogs.com/KiVen2015/p/8277316.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!