zoukankan      html  css  js  c++  java
  • iOS iOS8新特性--UIPopoverPresentationController

    1.回顾UIPopoverController的使用,下面这份代码只能在ipad下运行   

        

    // 初始化控制器,SecondViewController类继承自UIViewController
    
      SecondViewController *vc = [[SecondViewController alloc] init];
    
        // 把vc包装成UIPopoverController
    
        UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:vc];
    
      // 设置popover的指向,
    
      // 指向当前控制上button按钮,所以FromRect后跟bounds
    
      // 如果是指向当前控制的View,则FromRect后跟frame
    
        [popover presentPopoverFromRect:self.button.bounds inView:self.button permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

    2. 运用UIPopoverPresentationController,下面这份代码在iphone和ipad中,都可以正常运行

    2.1 在iphone中是常见的modal方式,也就是从屏幕底部爬上来,而在ipad中,是popover的那种方式

     

    // 初始化控制器
    
        SecondViewController *vc = [[SecondViewController alloc] init];
    
        // modal出来是个popover
    
        vc.modalPresentationStyle = UIModalPresentationPopover;
    
        // 取出vc所在的UIPopoverPresentationController
    
        vc.popoverPresentationController.sourceView = self.button;
    
        vc.popoverPresentationController.sourceRect = self.button.bounds;
    
        [self presentViewController:vc animated:YES completion:nil];

    2.2 在iphone中,上面这份代码等同于下面:

        

    2.3 苹果在iOS8中对UIViewController做了类扩展

      也就是说popoverPresentationController是UIViewController的属性

      modalPresentationStyle是UIViewController成员变量

      UIPopoverPresentationController继承自UIPresentationController, UIPresentationController又继承自NSObject

  • 相关阅读:
    同志们的毒害1_xuhang01
    2019佳木斯集训 Day8
    2019佳木斯集训 Day7
    2019佳木斯集训 Day6
    2019佳木斯集训 Day5
    数据结构——关于倍增LCA那点事
    2019佳木斯集训 Day3
    2019佳木斯集训 Day4
    centos7安装python2 sybase相关依赖
    mac与centos终端快捷指令
  • 原文地址:https://www.cnblogs.com/fengmin/p/5577969.html
Copyright © 2011-2022 走看看