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

  • 相关阅读:
    02day-webpack
    Mybatis中的@Param注解(自己没试过)
    SpringMVC
    jsp获取map
    form表单提交时选择性传值到后台
    form表单提交数据的几种方式
    ajax中什么时候进success和error
    @RequestParam加与不加的区别
    @RequestBody和@RequestParam区别
    java.lang.IllegalArgumentException: Invalid character found in the request target. The valid charact
  • 原文地址:https://www.cnblogs.com/fengmin/p/5577969.html
Copyright © 2011-2022 走看看