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. android103 内容观察者

    #内容观察者 * 通过内容提供者可以访问到数据库,当数据库数据改变时,内容提供者会发出通知,在内容提供者的uri上注册一个内容观察者,就可以收到数据改变的通知,类似于广播接受者,但是他不是广播. cr ...

  2. 标准I/O库之定位流

    有三种方法定位标准I/O流. (1)ftell和fseek函数.这两个函数自V7以来就存在了,但是它们都假定文件的位置可以存放在一个长整型中. (2)ftello和fseeko函数.Single UN ...

  3. Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解实例详解(五)

    这是本系列的最后一篇,主要讲一下FreeMarker模板引擎的基本概念与常用指令的使用方式.     一.FreemMarker基本概念     FreemMarker是一个用Java语言编写的模板引 ...

  4. Python之路【第二十二篇】:Django之Model操作

    Django之Model操作   一.字段 AutoField(Field) - int自增列,必须填入参数 primary_key=True BigAutoField(AutoField) - bi ...

  5. 使用 Date 和 SimpleDateFormat 类表示时间

    在程序开发中,经常需要处理日期和时间的相关数据,此时我们可以使用 java.util 包中的Date类.这个类最主要的作用就是获取当前时间,我们来看下Date的类的使用: Date d=new Dat ...

  6. Activity 的生命周期与加载模式

    当Activity 处于Android 应用中运行时,它的活动状态由 Android 以 Activity 栈的形式管理.当前活动的Activity位于栈顶.随着不同应用的运行,每个Activity都 ...

  7. web开发学习之旅---html第一天

    一.认识浏览器 浏览器就是接收浏览着的操作,然后帮浏览者去web服务器请求网页内容(html格式返回),然后展现成人眼能够看得懂的可视化页面的软件. IE==浏览器?IE是浏览器的一种,还有Firef ...

  8. 达夫设备/达夫算法(Duff's Device)

    主要是下面的代码: register n = (count + 7) / 8;   /\* count > 0 assumed \*/ switch (count % 8) { case 0:  ...

  9. iOS toolbar

    初学ios,对toolbar初步了解: self.navigationItem.title=@"显示工具栏"; // 显示工具栏 //self.navigationControll ...

  10. Android----二维码开发

    Android----二维码开发 本文为原创,转载请注明出处:http://www.cnblogs.com/xiaobaicai12138/p/5644244.html 一.工具 谷歌的zxing 不 ...