一、以往使用 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. jQuery实现自动调用和触发某个事件的方法

    1.比如我们通过jquery定义了一个点击事件,我们如何自动触发他: $(function(){    $('#button').click(function(){      alert('butto ...

  2. ios Develop mark

    App Distribution Guidehttps://developer.apple.com/library/ios/documaentation/IDEs/Conceptual/AppDist ...

  3. Oracle分析関数

    Oracleの分析関数のサンプル集 概要 Oracleコミュニティでよく見かける分析関数の使用例を 習うより慣れろ形式で.分析関数のイメージを付けて.まとめて紹介します. Oracle11gR1で動作 ...

  4. [AX2012]关于财务默认维度

    和以前的版本一样,AX2012中很多地方都使用财务维度,比如客户.销售订单.销售订单行等,根据相应的财务维度设置,生成的相应财务分录将带有财务维度,方便后续对财务分录交易的分析.下图是在客户记录上设置 ...

  5. linux-指定特殊域去重

    测试数据: 2017-10-24 14:14:11:1123 [ INFO] order_type=add,order_id=9152017-10-24 14:14:11:1123 [ INFO] o ...

  6. OSG3.4编译FFMPEG插件

    0.加入你要读a.mp4,那个正确的写法是osg::Image* image = osgDB::readImageFile("a.mp4.ffmpeg"); 1.在github上下 ...

  7. pip导出安装包及批量安装

    python导出安装包及版本 pip freeze > requirements.txt 批量安装pip install -r requirements.txt

  8. delphi调用存储过程

    一 . TAdoQuery对象下 1. mysql存储过程 sqls := Format(' call pro_addOneStudent (' + '''%s'',''%s'',''%s'',''% ...

  9. WinPE启动U盘的制作方法与软件下载(通用PE工具箱/老毛桃/大白菜WinPE)

    转自:http://blog.sina.com.cn/s/blog_58c380370100cp5x.html 文件大小:39.5M(支持Win7安装,早期的通用PE工具箱,小巧不过几十兆,现在都臃肿 ...

  10. 【.NetCore学习】ASP.NET Core EF Core2.0 DB First现有数据库自动生成实体Context

    主要参考微软官方文档 https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db Microsoft .NE ...