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

    }

  • 相关阅读:
    Sublime Text 3 快捷键精华版
    css动画+滚动的+飞舞的小球
    css动画+照片清晰度动画
    simhash
    抛弃IIS,利用FastCGI让Asp.net与Nginx在一起
    不逃离WIndows,Asp.Net就只能写写进销存管理系统
    吸引下百度蜘蛛
    Arcpy功能总结
    英雄杀
    NCEP Datasets
  • 原文地址:https://www.cnblogs.com/guangleijia/p/5038391.html
Copyright © 2011-2022 走看看