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. linux下启动某个进程

    在关闭窗口的情况下,能够在后台继续运行,如 启动命令 node /home/node_modules/pixel-ping/lib/pixel-ping.js /home/node_modules/p ...

  2. UDP包的最大大小是多少?

      每个udp包的最大大小是多少?    65507 约等于 64K 为什么最大是65507?    因为udp包头有2个byte用于记录包体长度. 2个byte可表示最大值为: 2^16-1=64K ...

  3. 第一篇:GPU 编程技术的发展历程及现状

    前言 本文通过介绍 GPU 编程技术的发展历程,让大家初步地了解 GPU 编程,走进 GPU 编程的世界. 冯诺依曼计算机架构的瓶颈 曾经,几乎所有的处理器都是以冯诺依曼计算机架构为基础的.该系统架构 ...

  4. Volley完全解析

    从前在学校用的最多的网络请求框架就是AsyncHttpClient,用久了发现这样一个问题,就是代码复用太难,基本上做不到,所以有一段时间又回归了HttpURLConnection和HttpClien ...

  5. 集合练习——Set部分

    我们知道list存储的是有序不唯一的元素. set存储的是无序唯一的元素. 那么下面看一个例子吧: package CollectionPart; import java.util.HashSet; ...

  6. C++ notes for beginners(2)

    作者:马 岩(Furzoom) (http://www.cnblogs.com/furzoom/)版权声明:本文的版权归作者与博客园共同所有.转载时请在明显地方注明本文的详细链接,未经作者同意请不要删 ...

  7. webrtc学习——RTCPeerConnection

    The RTCPeerConnection interface represents a WebRTC connection and handles efficient streaming of da ...

  8. 调试环境部署续:vs远程调试

    原文http://www.bitscn.com/weixin/464994.html 第一步  IIS的配置 进入iis,点击网址,选择你的网站,在窗口的右边编辑网站中点击绑定,如图所示. 进入网站绑 ...

  9. HeaderViewListAdapter cannot be cast to listAdapter问题原因及解决办法

    [o] 在listView中添加leaderView 和footerView的时候要注意在setAdapter之前调用,不然会报如下异常: listAdapter cannot be cast to ...

  10. EditText属性详解

    关于EditText属性详解很详细的记录,转过来收着 1.EditText输入的文字为密码形式的设置 (1)通过.xml里设置: 把该EditText设为:android:password=" ...