iOS8.0之后, 苹果推出了UIPopoverPresentationViewController, 在弹出控制器时, 统一采用 presentViewController,

但是要实现iPhone和iPad能够统一使用一段代码, 需要进行一些设置:

@implementation ViewController

// UIPopoverController只能用在iPad

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically fro

}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

HMSecondViewController *vc = [[HMSecondViewController alloc] init];

// modal出来是个popover

vc.modalPresentationStyle = UIModalPresentationPopover;

// 取出vc所在的UIPopoverPresentationController

vc.popoverPresentationController.sourceView = self.slider;

vc.popoverPresentationController.sourceRect = self.slider.bounds;

[self presentViewController:vc animated:YES completion:nil];

}

@end

例如: UIAlertController

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"警告" message:@"你有严重的精神病,赶紧去治疗" preferredStyle:UIAlertControllerStyleActionSheet];

// 默认是POPover

alert.modalPresentationStyle = UIModalPresentationPopover;

// 设置popover指向的item

//    alert.popoverPresentationController.barButtonItem = self.navigationItem.leftBarButtonItem;

alert.popoverPresentationController.sourceView = _clickBtn;

alert.popoverPresentationController.sourceRect = _clickBtn.bounds;

// 添加按钮

[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {

NSLog(@"点击了确定按钮");

}]];

[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

NSLog(@"点击了取消按钮");

}]];

[self presentViewController:alert animated:YES completion:nil];

}

iphone 与 ipad -- UIPopoverPresentationViewController的更多相关文章

  1. 在Mac电脑上为iPhone或iPad录屏的方法

    在以前的Mac和iOS版本下,录制iPhone或者iPad屏幕操作是一件稍微复杂的事情.但是随着Yosemite的出现,在Mac电脑上为iPhone或iPad录屏的方法就变得简单了.下面就介绍一下具体 ...

  2. iPhone与iPad在开发上的区别

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  3. iOS 为iPhone和iPad创建不同的storyboard

    复制Main.storyboard,重命名为Main_iPad.storyboard 在info.plist文件中添加 Main storyboard file base name (iPad) -- ...

  4. css去掉iPhone、iPad默认按钮样式

    原文链接:http://blog.sina.com.cn/s/blog_7d796c0d0102uyd2.html 只要在样式里面加一句去掉css去掉iPhone.iPad的默认按钮样式就可以了!~ ...

  5. CRM2013版本 IOS APP 说明(IPhone、IPad)

    CRM2013版本 IOS APP 说明(IPhone.IPad) IPhone版本 首页 CRM APP在登录时输入账号信息,可以进行首面.其首页显示内容可以在CRM后台设置. 系统默认显示:Pho ...

  6. Iphone和iPad适配, 横竖屏

    竖屏情况下: [UIScreen mainScreen].bounds.size.width = 320 [UIScreen mainScreen].bounds.size.width = 568 横 ...

  7. 【转】越狱的 iPhone、iPad 通过网站实现一键安装 ipa 格式的 APP 应用

    1.已经越狱的 iPhone.iPad 设备,当通过其自带的 safari 浏览器访问 ipa 应用下载网站时,利用 itms-services 协议,可以一键安装 ipa 文件的 iOS 应用,例如 ...

  8. Professional iOS Network Programming Connecting the Enterprise to the iPhone and iPad

    Book Description Learn to develop iPhone and iPad applications for networked enterprise environments ...

  9. daily news新闻阅读客户端应用源码(兼容iPhone和iPad)

    daily news新闻阅读客户端应用源码(兼容iPhone和iPad),也是一款兼容性较好的应用,可以支iphone和ipad的阅读阅读器源码,设计风格和排列效果很不错,现在做新闻资讯客户端的朋友可 ...

随机推荐

  1. 标准I/O库之打开和关闭流

    下列三个函数打开一个标准I/O流. #include <stdio.h> FILE *fopen( const char *restrict pathname, const char *r ...

  2. linux监控程序

    IP内部地址: 方法一:ifconfig |grep 'inet addr'|grep '192.168.1' | awk '{print $2}'| tr -d "addr:" ...

  3. C#读取Exeal文件

    今天写一个读取Exeal的时候遇到一个问题就是引用了Mircosotf.Office.Interop.Exeal类库的时候没有办法读取到 纠结了好久百度了一下发现别人是这样写的using Exeal= ...

  4. commons-io源码阅读心得

    FileCleanTracker: 开启一个守护线程在后台默默的删除文件. /* * Licensed to the Apache Software Foundation (ASF) under on ...

  5. Fragment碎片频繁来回切换的时候报java.lang.IllegalStateException: No activity

    出现这个问题的原因是因为使用的transcation.replace(fragmentTwo);的方式进行碎片切换的. 解决方案是使用add和show.hide方法组合实现碎片的切换(应该是显示.隐藏 ...

  6. tcl/tk实例详解——返回一个文件夹下所有文件的绝对路径

    http://blog.csdn.net/dulixin/article/details/2133840 #所有代码如下,使用注释的方式讲解脚本#修改好文件夹和保存结果路径,可以把本文件直接拷贝进tc ...

  7. 万网免费主机wordpress快速建站教程-wordpress下载及安装

    进入wordpress官网(http://cn.wordpress.org)下载最新的wordpress安装程序,下载完成后解压到任意电脑目录. 解压完毕后,使用FTP管理工具上传安装文件至主机htd ...

  8. Unity3D 之UGUI 面板

    UGUI中使用面板,可以对一组控件分为一个组. 一个面板里面可以添加一些控件,就如同Html中的<div>一样.

  9. C#学习笔记(4)

    今天先把上几个系列的做一个总结,在这里给出一个面向对象版的简易计算器(重在理解面向对象的思想). 1.首先定义一个计算器类(类库)(Calculator) public abstract class ...

  10. 直播类送礼动画<豪华礼物+小礼物>

    直播类送礼动画<豪华礼物+小礼物>:代码会持续更新,现直播的app里内有太多的动画,由于时间关系不能一次共享所有动画聘为,这次先共享几个比较火爆的动画. 支持真机和模拟器上运行,最低支持i ...