iOS8新特性(2)——UIPopoverController和UIPresentationController
2015-08-30 11:01
417 查看
一、以往使用 UIPopoverController
都是只在iPad上使用
二、统一的方式:
三、机制
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
都是只在iPad上使用
/** * UIPopoverController 只能用于iPad,上,iPhone上使用会崩溃 */ -(void)old { VC2 *vc = [[VC2 alloc]init]; UIPopoverController *popover = [[UIPopoverController alloc]initWithContentViewController:vc]; [popover presentPopoverFromRect:self.btn.bounds inView:self.btn permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; }
二、统一的方式:
-(void)new { VC2 *vc = [[VC2 alloc]init]; //下面三行代码在iPhone中是会被忽略的 //但是在iPad中是将我们的present当作是present一个popover //所以这是一种比较好的适配iPhone和iPad的共存方法 vc.modalPresentationStyle = UIModalPresentationPopover; vc.popoverPresentationController.sourceRect = self.btn.bounds; vc.popoverPresentationController.sourceView = self.btn; [self presentViewController:vc animated:YES completion:nil]; }
- (void)viewDidLoad { [super viewDidLoad]; ViewController2 *vc2 = [[ViewController2 alloc]init]; //vc2.modalPresentationStyle = UIModalPresentationFormSheet;//弹出在中间 vc2.modalPresentationStyle = UIModalPresentationPopover; //popover的形式弹出 vc2.popoverPresentationController.barButtonItem = self.navigationItem.leftBarButtonItem; [self presentViewController:vc2 animated:YES completion:nil]; }
三、机制
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
相关文章推荐
- iOS8新特性(1)——UIAlertController
- 编写广播时出现Exported receiver does not require permission
- 学习YUI.Ext 第一天:EXT简介(一)
- HOWTO: Install, Build and Use openCV (MacOSX 10.10)
- POJ 2524 Ubiquitous Religions(宗教种类:并差集)
- adbd cannot run as root in production builds
- iphone开发之表格组件UITableView的使用(一)使用时的具体步骤介绍
- UUID.randomUUID().toString 简单解释
- CodeForces 441A Valera and Antique Items
- iOS开发 - UICollectionViewLayout 自定义布局
- iOS开发 - UICollectionViewFlowLayout 流水布局
- UIday02~04:UITextField UIButton UIdelegate 自定义视图 容器视图控制器
- POJ 3458 && HDU 1683 Colour Sequence(水~)
- Win10 Build 10532语言包官方下载地址汇总
- POJ 3094 && HDU 2734 Quicksum(水~)
- esayyui的layout嵌套布局可以解决fit自适应的位置偏移问题
- HDU1005 - Number Sequence (矩阵快速幂)
- Arduino CNC Shiled 和 DRV8825驱动板的注意事项
- UICollectionView
- Arduino 3G shield using SoftwareSerial to control