一、以往使用 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. winform下通过webclient使用非流方式上传(post)数据和文件

    这两天因为工作的需要,需要做一个winform上传数据到服务器端的程序.当时第一个想法是通过webservice的方式来实现,后来觉得麻 烦,想偷懒就没有用这样的方式,http的post方式变成了第一 ...

  2. eclipse中开发js会卡,去掉.project中的validate即可

    注释掉 <buildCommand> <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name> & ...

  3. SpringBoot------使用Fastjson解析Json数据

    方法一: 1.在pom.xml文件下添加依赖包 <dependency> <groupId>com.alibaba</groupId> <artifactId ...

  4. XMPP协议实现即时通讯底层书写 (一)--从RFC6121阅读開始

    Extensible Messaging and Presence Protocol (XMPP): Instant Messaging and Presence ok,额瑞巴蒂,说好的阅读RFC61 ...

  5. Java -- Java 类集 -- 目录

    13.1 认识类集 13.1.1 基本概念 13.1.2 类集框架主要接口 13.2 Collection接口 13.2.1 Collection接口的定义 13.2.2 Collection子接口的 ...

  6. 8 -- 深入使用Spring -- 3...1 Resource实现类

    8.3.1 Resource实现类 Resource接口是Spring资源访问的接口,具体的资源访问由该接口的实现类完成. Spring提供的Resource接口的实现类: ⊙ UrlResource ...

  7. Unity3D Shader官方教程翻译(十九)----Shader语法,编写表面着色器

    Writing Surface Shaders Writing shaders that interact with lighting is complex. There are different ...

  8. Lua 迭代器与closure

    所谓“迭代器”就是一种可以遍历(iterate over)一种极和中所有元素的机制.在Lua中,通常将迭代其表示为函数.每调用一次函数,即返回集合中的“下一个”元素.每个迭代器都需要在每次成功调用之间 ...

  9. Python正则表达式 学习笔记

    python第一个正则表达式 1. import re : python正则表达式模块 2. 第一个正则表达式 re.compile(r'imooc') pattern.match('imooc py ...

  10. 《转载》renameTo文件在windows环境下可以,在linux中报错

    以前我一直以为File#renameTo(File)方法与OS下面的 move/mv 命令是相同的,可以达到改名.移动文件的目的.不过后来经常发现问题:File#renameTo(File)方法会返回 ...