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中,上面这份代码等同于下面:

        SecondViewController *vc = [[SecondViewController alloc] init];

        /* 相当于中间3行代码不存在

        vc.modalPresentationStyle = UIModalPresentationPopover;

        vc.popoverPresentationController.sourceView = self.button;

        vc.popoverPresentationController.sourceRect = self.button.bounds;  

        */

        [self presentViewController:vc animated:YES completion:nil];

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

      也就是说popoverPresentationController是UIViewController的属性

      modalPresentationStyle是UIViewController成员变量

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

  • 相关阅读:
    uva129
    uva167
    【Linux】touch命令
    【Linux】od命令
    【Linux】tail命令
    【Linux】head命令
    【Linux】less命令
    【Linux】more命令
    【Linux】nl命令
    【Linux】cat命令
  • 原文地址:https://www.cnblogs.com/oumygade/p/4275734.html
Copyright © 2011-2022 走看看