zoukankan      html  css  js  c++  java
  • iphone 与 ipad -- UIPopoverPresentationViewController

      iOS8.0之后, 苹果推出了UIPopoverPresentationViewController, 在弹出控制器时, 统一采用 presentViewController,

    但是要实现iPhone和iPad能够统一使用一段代码, 需要进行一些设置:

     

    @implementation ViewController

    // UIPopoverController只能用在iPad

    - (void)viewDidLoad {

        [super viewDidLoad];

        // Do any additional setup after loading the view, typically fro

    }

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

        HMSecondViewController *vc = [[HMSecondViewController alloc] init];

        // modal出来是个popover

        vc.modalPresentationStyle = UIModalPresentationPopover;

        // 取出vc所在的UIPopoverPresentationController

        vc.popoverPresentationController.sourceView = self.slider;

        vc.popoverPresentationController.sourceRect = self.slider.bounds;

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

        }

    @end

    例如: UIAlertController

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {    

        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"警告" message:@"你有严重的精神病,赶紧去治疗" preferredStyle:UIAlertControllerStyleActionSheet];

        // 默认是POPover

        alert.modalPresentationStyle = UIModalPresentationPopover;

        // 设置popover指向的item

    //    alert.popoverPresentationController.barButtonItem = self.navigationItem.leftBarButtonItem;

        alert.popoverPresentationController.sourceView = _clickBtn;

        alert.popoverPresentationController.sourceRect = _clickBtn.bounds;

        // 添加按钮

        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {

            NSLog(@"点击了确定按钮");

        }]];

        [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

            NSLog(@"点击了取消按钮");

        }]];

        

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

    }

  • 相关阅读:
    java中的泛型
    那些java中的包装类
    那些java中的内部类
    那些java中的常用类(二)
    那些java中的常用类(一)
    java中的反射机制浅析
    java中的垃圾回收机制浅析
    java中equals与==的用法浅析
    在iOS项目中,这样才能完美的修改项目名称
    最新的 iOS 申请证书与发布流程
  • 原文地址:https://www.cnblogs.com/guangleijia/p/5038391.html
Copyright © 2011-2022 走看看