一、以往使用 UIPopoverController

  都是只在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新特性(2)——UIPopoverController和UIPresentationController的更多相关文章

  1. iOS8 新特性

    iOS8新特性主要体现在4方面 1.UIAlertController 对alert&actionSheet的封装 UIAlertController.h 提示框按钮的选择 typedef N ...

  2. iOS8新特性(1)——UIAlertController

    一.iOS8介绍 iOS8 新特性,主要是UI上进行了统一 1.UIAlertController 2.UIPresentaionController:管理所有通过modal出来的控制器(看笔记) 3 ...

  3. ios8新特性widget开发-b

    os8发布已经有一段时间了,伴随着ios8同时也出现了许多新的特性,ios系统将会越来越开放,这是好事.其中一个新特性就是在下拉通知栏里加入了个性的widget,开发者可以自己定义widget的样式内 ...

  4. iOS8新特性

    1. App Extension Programming Guide 2.LocalAuthentication.framework - Touch ID Authentication 3.Local ...

  5. iOS iOS8新特性--UIPopoverPresentationController

    1.回顾UIPopoverController的使用,下面这份代码只能在ipad下运行 // 初始化控制器,SecondViewController类继承自UIViewController Secon ...

  6. iOS8新特性(1)-UIPopoverPresentationController使用

    从iOS 8开始,苹果提出新的 UIPopoverPresentationController代替UIPopoverController: 新的UIPopoverPresentationControl ...

  7. 利用iOS8新特性计算cell的实际高度

    在计算cell的实际高度是 我们一般是通过计算frame  拿到最底部一个控件的最大Y值从而的到cell 的高度  算来算去  比较麻烦 其实,iOS8已经提供了直接通过Cell高度自适应的方法了,根 ...

  8. iOS8新特性之基于地理位置的消息通知UILocalNotification

              苹果在WWDC2014上正式公布了全新的iOS8操作系统. 界面上iOS8与iOS7相比变化不大,只是在功能方面进行了完好.                             ...

  9. iOS8新特性之交互式通知

    目前分为四个推送:用户推送,本地推送,远程推送,地理位置推送. if (IS_IOS8) { //1.创建消息上面要添加的动作(按钮的形式显示出来) UIMutableUserNotification ...

随机推荐

  1. 8. Django系列之上传文件与下载-djang为服务端,requests为客户端

    preface 运维平台新上线一个探测功能,需要上传文件到服务器上和下载文件从服务器上,那么我们就看看requests作为客户端,django作为服务器端怎么去处理? 对于静态文件我们不建议通过dja ...

  2. lua:值得看的博客资源 ...

    凯奥斯 :https://blog.csdn.net/ecidevilin/article/category/6454847 https://blog.csdn.net/qinyuanpei/arti ...

  3. QT 运行崩溃:The inferior stopped because it received a signal from the Operating System

    最近在研究QT自带的boxes例子,自己派生一个图形项,但是在运行生成该图形项时程序直接退出了~ Qt Creater调试代码,问题定位如下代码行: 执行1270行时弹出错误消息框: 于是上网查找资料 ...

  4. Centos修改时间显示的时区,将UTC修改为CST

    问题说明: 今天一同事反应,系统的时间不对和正常的时间差8个小时.就登录主机看了下时间 系统时间显示为: # date Fri Dec :: UTC # 备注:查看了下,正好和当前的时间差了8个小时. ...

  5. IE每次关闭都提示IE已停止工作

    方法一:打开IE浏览器,点击工具,选择下拉菜单中的internet选项,切换至高级选项卡标签,找到“启用第三方浏览器扩展”选项.把前面的打勾去掉: 方法二:打开IE浏览器,不管是6.0还是更高的版本这 ...

  6. iOS AppsFlyer的使用注意事项

    AppFlyer 是近期比較火的一款广告追踪统计工具,当然统计的功能友盟也能够实现,而appsflyer更是具有定向投放,是app跳转到对应的页面. 详细的:当点击广告的时候,假设没有安装应用.则会跳 ...

  7. 8 -- 深入使用Spring -- 2...5 Spring 3.0 新增的注解

    8.2.5 Spring 3.0 新增的注解 @DependsOn @Lazy @DependsOn :用于强制初始化其他Bean.修饰Bean类或方法,可以指定一个字符串数组作为参数,每个数组元素对 ...

  8. WPF导航总结

    使用导航的目的是从一个页面进入到另一个页面.无论是预先决定的线性顺序(向导)还是基于层次的用户驱动程序(大部分网站的形式),或者动态生成的路径,主要有3种方法实现:调用Navigate方法,使用Hyp ...

  9. C++ 默认构造函数小记

    #include <string> #include <map> using namespace std; class A { public: A(string name):n ...

  10. Kafka controller重设计

    本文主要参考社区0.11版本Controller的重设计方案,试图给大家梳理一下Kafka controller这个组件在设计上的一些重要思考.众所周知,Kafka中有个关键组件叫controller ...