博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS8新特性(2)——UIPopoverController和UIPresentationController
阅读量:7089 次
发布时间:2019-06-28

本文共 1896 字,大约阅读时间需要 6 分钟。

一、以往使用 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

 

转载地址:http://feyql.baihongyu.com/

你可能感兴趣的文章
Ceph实验室:第五课:Ceph运维之换盘
查看>>
C++实践参考——复数类中的运算符重载
查看>>
【Spark Summit East 2017】为了乐趣和利润的全球扩张
查看>>
Rss订阅
查看>>
Mac - gdb配置
查看>>
Vuejs——(4)v-if、v-for
查看>>
让Spark成为你的瑞士军刀
查看>>
[LeetCode]--40. Combination Sum II
查看>>
ART世界探险(16) - 快速编译器下的方法编译
查看>>
多线程常用方法 sleep wait join等以及对锁的控制
查看>>
MPEG-DASH新功能白皮书翻译
查看>>
关于图片在内存中的大小(k或者M)
查看>>
2018 一份"有点难"的iOS面试题(5年iOS开发)
查看>>
linux mint19-日常使用笔记
查看>>
如何快速掌握一个ui框架
查看>>
git过滤
查看>>
web开发安全框架中的Apache Shiro的应用
查看>>
赵童鞋带你入门PHP(一) 开发环境搭建
查看>>
JavaScript 七大继承全解析
查看>>
nginx正则表达式(上篇)
查看>>