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];

    }

  • 相关阅读:
    cookie,sessionStorage,localStorage
    存储方式与传输方式
    为什么css放在顶部而js写在后面
    常见的web安全及防护原理
    web缓存
    http协议理解
    http与https
    get/post的区别
    JZOJ 3571. 【GDKOI2014】内存分配
    JZOJ 3570. 【GDKOI2014】壕壕的寒假作业
  • 原文地址:https://www.cnblogs.com/guangleijia/p/5038391.html
Copyright © 2011-2022 走看看