iphone 与 ipad -- UIPopoverPresentationViewController
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的更多相关文章
- 在Mac电脑上为iPhone或iPad录屏的方法
在以前的Mac和iOS版本下,录制iPhone或者iPad屏幕操作是一件稍微复杂的事情.但是随着Yosemite的出现,在Mac电脑上为iPhone或iPad录屏的方法就变得简单了.下面就介绍一下具体 ...
- iPhone与iPad在开发上的区别
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- iOS 为iPhone和iPad创建不同的storyboard
复制Main.storyboard,重命名为Main_iPad.storyboard 在info.plist文件中添加 Main storyboard file base name (iPad) -- ...
- css去掉iPhone、iPad默认按钮样式
原文链接:http://blog.sina.com.cn/s/blog_7d796c0d0102uyd2.html 只要在样式里面加一句去掉css去掉iPhone.iPad的默认按钮样式就可以了!~ ...
- CRM2013版本 IOS APP 说明(IPhone、IPad)
CRM2013版本 IOS APP 说明(IPhone.IPad) IPhone版本 首页 CRM APP在登录时输入账号信息,可以进行首面.其首页显示内容可以在CRM后台设置. 系统默认显示:Pho ...
- Iphone和iPad适配, 横竖屏
竖屏情况下: [UIScreen mainScreen].bounds.size.width = 320 [UIScreen mainScreen].bounds.size.width = 568 横 ...
- 【转】越狱的 iPhone、iPad 通过网站实现一键安装 ipa 格式的 APP 应用
1.已经越狱的 iPhone.iPad 设备,当通过其自带的 safari 浏览器访问 ipa 应用下载网站时,利用 itms-services 协议,可以一键安装 ipa 文件的 iOS 应用,例如 ...
- 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 ...
- daily news新闻阅读客户端应用源码(兼容iPhone和iPad)
daily news新闻阅读客户端应用源码(兼容iPhone和iPad),也是一款兼容性较好的应用,可以支iphone和ipad的阅读阅读器源码,设计风格和排列效果很不错,现在做新闻资讯客户端的朋友可 ...
随机推荐
- [RxJS] Drag and Drop example
Improving our mouse drag event Our mouse drag event is a little too simple. Notice that when we drag ...
- Monitoring and Tuning the Linux Networking Stack: Receiving Data
http://blog.packagecloud.io/eng/2016/06/22/monitoring-tuning-linux-networking-stack-receiving-data/ ...
- ant有什么用
内容摘要: ANT是一个基于Java的自动化脚本引擎,脚本格式为XML.除了做Java编译相关任务外,ANT还可以通过插件实现很多应用的调用. 1)ANT的基本概念: 2)ANT的安装:解包,设置路径 ...
- Java基础知识强化之IO流笔记50:IO流练习之 复制多级文件夹的案例
1. 复制多级文件夹的案例 需求:复制多级文件夹 数据源:E:\JavaSE\day21\code\demos 目的地:E:\ 分析: A:封装数据源File ...
- android的activity的跳转
1.无参数的跳转 先在layout下建立一个factivity.xml,在里面添加2个Button按钮和一个TextView,并添加属性 , 然后建立以个sactivity.xml文件, 在src下建 ...
- string与StringBuilder之性能比较
知道“StringBuilder比string性能强”好多年了,近日无聊病发作,就把这两个家伙给动了手术: using System; using System.Text; namespace Con ...
- 请编程实现:产生一个int数组,长度为100,并向其中随机插入1-100,并且不能重复(百度了一下,get一种高性能算法,非递归)
网上找到一种更好的实现方式: (1)把N个数放到容器A(int数组)中. (2)从N个数中随机取出1个数放入容器B(int数组)中. (3)把容器A中最后一个数与随机抽取的数对调 或者 把容器A中最后 ...
- ASP.NET MVC之PagedList使用
ASP.NET MVC之PagedList使用 ---由于最近项目中用到了分页这里也来记录一下,一方面给自己一个记录,另一方面给后来者一些帮助! 一.首先大家先来看一下效果
- SQL Server调优系列基础篇 - 联合运算符总
前言 上两篇文章我们介绍了查看查询计划的方式,以及一些常用的连接运算符的优化技巧,本篇我们总结联合运算符的使用方式和优化技巧. 废话少说,直接进入本篇的主题. 技术准备 基于SQL Server200 ...
- Spring.net架构示例(含Aop和Ioc)源码
最近写了一个Spring.net的架构. 一.架构主图 架构图的数据流程走向是: UI层=>UILogic>=>Service>Business=>DataAccess ...