zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    支持向量机(二)
    kafka partiton迁移方法与原理
    park和unpark
    Replicated State Machine和WAL
    thrift源码分析
    thrift使用和源码分析
    kafka源码环境搭建
    kafka指定partiton生产
    gradle构建scala
    kafka consumer代码梳理
  • 原文地址:https://www.cnblogs.com/daomul/p/4770469.html
Copyright © 2011-2022 走看看