调用系统的相机

设置两个代理即:UINavigationControllerDelegate,UIImagePickerControllerDelegate


-(void)headBClick{

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

    //设置代理

    controlImg.delegate=self;

    //是否编辑

    controlImg.allowsEditing=YES;

   //初始化弹出对象

    UIAlertController *alterC=[UIAlertController alertControllerWithTitle:@"" message:@"选择照片" preferredStyle:UIAlertControllerStyleActionSheet];

   //初始化选项事件

    UIAlertAction *action=[UIAlertAction actionWithTitle:@"选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

        //设置类型

        controlImg.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;

        //弹出图片视图

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

            

        }];

    }];

    [alterC addAction:action];

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        UIAlertAction *action2=[UIAlertAction actionWithTitle:@"选择相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

            //设置类型

            controlImg.sourceType=UIImagePickerControllerSourceTypeCamera;

            //弹出

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

                

            }];

        }];

        [alterC addAction:action2];

    }

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

        

    }];

   //初始化选项事件

    UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

        

    }];

    [alterC addAction:action3];


}


#pragma Mark 取消照片代理

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{

    [self dismissViewControllerAnimated:YES completion:^{

        

    }];

}


-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{

//    NSLog(@"%@",info);

    [headB setImage:info[UIImagePickerControllerOriginalImage] forState:UIControlStateNormal];

    [self dismissViewControllerAnimated:YES completion:^{

        

    }];


}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冉然

你的鼓励对我很重要

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值