• iOS8新特性(2)——UIPopoverController和UIPresentationController


    一、以往使用 UIPopoverController

      都是只在iPad上使用

     1 /**
     2  *  UIPopoverController 只能用于iPad,上,iPhone上使用会崩溃
     3  */
     4 -(void)old
     5 {
     6     VC2 *vc = [[VC2 alloc]init];
     7     
     8     UIPopoverController *popover = [[UIPopoverController alloc]initWithContentViewController:vc];
     9     [popover presentPopoverFromRect:self.btn.bounds inView:self.btn permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    10 }

    二、统一的方式:

     1 -(void)new
     2 {
     3     VC2 *vc = [[VC2 alloc]init];
     4     
     5     //下面三行代码在iPhone中是会被忽略的
     6     //但是在iPad中是将我们的present当作是present一个popover
     7     //所以这是一种比较好的适配iPhone和iPad的共存方法
     8     vc.modalPresentationStyle = UIModalPresentationPopover;
     9     vc.popoverPresentationController.sourceRect = self.btn.bounds;
    10     vc.popoverPresentationController.sourceView = self.btn;
    11     
    12     [self presentViewController:vc animated:YES completion:nil];
    13 }
     1 - (void)viewDidLoad {
     2     [super viewDidLoad];
     3     
     4     ViewController2 *vc2 = [[ViewController2 alloc]init];
     5     
     6     //vc2.modalPresentationStyle = UIModalPresentationFormSheet;//弹出在中间
     7     vc2.modalPresentationStyle = UIModalPresentationPopover; //popover的形式弹出
     8     vc2.popoverPresentationController.barButtonItem = self.navigationItem.leftBarButtonItem;
     9     
    10     [self presentViewController:vc2 animated:YES completion:nil];
    11     
    12 }

    三、机制

        1、只要一调用[self presentViewController:vc2 animated:YES completion:nil];

        2、首先会生成一个UIPresentationController

        3、然后由UIPresentationController管理控制器的切换

      4、无论设置UIModalPresentationFormSheet还是UIModalPresentationPopover模式,都是UIPresentationController来管理

    四、一些重要的属性

       UIPresentationController *p;

       p.presentingViewController; //底部正在弹出的控制器(主)

       p.presentedViewController;  //已经弹出来的控制器(被)

       p.presentedView;            //已经被弹出来的控制器的view

     vc2.presentationController;        //控制“已经弹出来的控制器” 的控制器:就是 p或者p的自控制器 (只读,内部采用懒加载的方式,所以不要去改)

     vc2.popoverPresentationController  //如果设置style为popover出来的就同上,否则不设置style或者设置其他style就是nil

  • 相关阅读:
    免费素材下载:淡蓝色的PSD格式UI套件
    分享一个CSS3的网格系统架构 ResponsiveAeon
    最新收集的超棒Mobile/Web UI和用户体验设计
    一个帮助你针对不同标签自动填入内容的轻量级javascript类库 fixiejs
    发现任何VB函数、插件、甚至按键精灵对“文件下载”窗口后台失效
    android 界面 滑入 效果
    分布式HeadLoop
    VB ListView
    android 下载保存图片
    网址
  • 原文地址:https://www.cnblogs.com/daomul/p/4770469.html
Copyright © 2020-2023  润新知