UIActionSheet和UIAlertController在iPhone和iPad上的那些事儿。

整理一下今天的所得。应该从哪里说起呢?

从今天用pad测试工程的时候发现工程中拍照上传没法用了。我用iphone可以用呀。一开始以为是系统的问题,升级了ios10之后不是有对相册,照相机等东西的私有设置吗,设置了白名单之后还是不可以。然后我就用断点打,发现是

    UIActionSheet *myActionSheet = [[UIActionSheet alloc]initWithTitle:nil

                                                              delegate:self

                                                     cancelButtonTitle:@"取消"

                                                destructiveButtonTitle:nil

                                                     otherButtonTitles:@"打开照相机",@"从手机相册获取",nil];

    

   [myActionSheet showInView:[UIApplication sharedApplication].keyWindow];

这段代码的问题

查了一下UIActionSheet再iPhone 和iPad上的显示是不同的。所以就改成了

 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"获取图片" message:nil preferredStyle: UIAlertControllerStyleActionSheet];

    

    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];

    

    UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"打开照相机" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {

        [self takePhoto];

    }];

    

    UIAlertAction *archiveAction = [UIAlertAction actionWithTitle:@"从手机相册获取" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

        [self LocalPhoto];

    }];

    

    [alertController addAction:cancelAction];

    

    [alertController addAction:deleteAction];

    

    [alertController addAction:archiveAction];

    alertController.popoverPresentationController.sourceView = [UIApplication sharedApplication].keyWindow.rootViewController.view;

    alertController.popoverPresentationController.sourceRect = CGRectMake(0,0,1.0,1.0);

    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertController animated:YES completion:nil];

   

这些才终于解决了。我们用的库是ZLPhotoLib,这是一个14年beiqing写的库。

注意哈:alertController.popoverPresentationController.sourceView = [UIApplication sharedApplication].keyWindow.rootViewController.view;

    alertController.popoverPresentationController.sourceRect = CGRectMake(0,0,1.0,1.0);这两句要是不指定可是会崩溃的这是UIAlertController的坑。

 

转载于:https://www.cnblogs.com/ma1314/p/6479388.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值