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. core dump + LINUX 内核系列博客

    参考:http://www.cnblogs.com/ahuo/category/72819.html http://blog.csdn.net/tenfyguo/article/details/815 ...

  2. 安装64位ubuntu 14.04-搭建android开发环境

                              end

  3. 摄像机(CCCamera)

  4. 【转】CCUserDefault类深入分析——2013-08-25 22

    http://game.dapps.net/gamedev/game-engine/8792.html 另:本章所用Cocos2d-x版本为: 2.1.1 (2013-01-28) 大家好,今天我们来 ...

  5. BULK INSERT将CSV或TXT文件导入到SQL Server

    CSV代表逗号分隔值,有时也被称为逗号分隔的值.而 如果加载txt文件,然后文件应该有逗号分隔的值.和文件应该是这样 下面是该脚本以创建表: CREATE TABLE Employee( Id int ...

  6. Hibernate的fetch (转)

    fetch ,可以设置fetch = "select" 和 fetch = "join" 用一对多来举例: fetch = "select" ...

  7. linux服务器下tomcat部署项目内存溢出

    今天将一个项目部署到linux服务器上,结果tomcat在启动运行到一定时间后就报错.根据以往的经验,查了一些资料,终于解决了该问题并顺便解决了生产环境中的get方式中文传递乱码问题. tomcat启 ...

  8. synchronized关键字小结(一)

    1. synchronized同步方法 1) synchronized修饰方法,表示方法是同步的,当某线程进入并拿到当前整个对象的锁时 a. 其他synchronized方法排队等锁 b. 非sync ...

  9. SQL Server数据的导入导出

    SQL Server 2008的导入导出服务可以实现不同类型的数据库系统的数据转换.为了让用户可以更直观的使用导入导出服务,微软提供了导入导出向导.导入和导出向导提供了一种从源向目标复制数据的最简便的 ...

  10. MVC小系列(十七)【自定义验证规则给下拉框】

    因为下拉框不支持验证,所以写一个attribute特性,让它继承ValidationAttributemvc的特性验证,很直接,无论是数据安全特性上还是页面表现上都不错,它的运行机制: 前台表单验证规 ...