iOS iOS8新特性--UIPresentationController


1. UIPresentationController的作用

  1>管理所有Modal出來的控制器

  2>管理通過這個方法  - (void) presentViewController:(UIViewController *) animated:(BOOL) completion:^(void)completion;顯示出來的控制器

  3>管理\監聽 切換控制器的過程

2. UIPresentationController的作用

  1>控制器一旦調了present方法,控制器的presentationController,會先創建好了,然后整個控制器的切換由presentationController管理

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

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

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

}

 

  2>控制器有2個屬性:presentationController和poppverPresentationController

    下面的截圖場景 vc.modalPresentationStyle = UIModalPresentationFormSheet, 這種情況下poppverPresentationController = nil 

  

  3>設置控制器以popver的方式切換.

    也就是說 vc.modalPresentationStyle = UIModalPresentationPopover,控制器的popoverPresentationController屬性就不再是nil了

    而且popoverPresentationController 和 presentationController 指向同一對象,指向的都是 UIPopoverPresentationController 類對象

    注: 1>UIPopoverPresentationController類 繼承自 UIPresentationController類

        2>父類指針可以指向子類,所以presentationController指向UIPopoverPresentationController對象,沒有問題

  4>控制器的presentationController 和 popoverPresentationController采用的是懶加載的方式,下面這段代碼,vc控制器是不會popover出來的.

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

    // 在 vc.popoverPresentationController.sourceView = self.segmented之前調了presentationController的get方法

  vc.presentationController; 

    vc.modalPresentationStyle = UIModalPresentationPopover;

    vc.popoverPresentationController.sourceView = self.segmented;

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM