• IOS 调用系统照相机和相册


     

    /**

     *  调用照相机

     */

    - (void)openCamera

    {

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

        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, nil, nil, nil);

        }

        

        [self dismissViewControllerAnimated:YES completion:nil];

    }

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

    - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

    {

        [self dismissViewControllerAnimated:YES completion:nil];

    }

  • 相关阅读:
    【WP8.1】富文本
    【WP8.1】WebView笔记
    【WP8】扩展CM的WindowManager
    随笔:关于关于
    <正则吃饺子> :关于微信支付的简单总结说明(二)
    <正则吃饺子> :关于微信支付的简单总结说明(一)
    <正则吃饺子> :关于Collections中 比较器的简单使用
    <正则吃饺子> :关于 Matcher 的 replaceAll 的简单使用
    <正则吃饺子> :关于oracle 中 with的简单使用
    <正则吃饺子> :关于oracle 中 exists 、not exists 的简单使用
  • 原文地址:https://www.cnblogs.com/xiangjune/p/5916599.html
Copyright © 2020-2023  润新知