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. HTML DOM对象

    HTML DOM对象 Document对象每个载入浏览器的HTML文档都会成为Document对象Document对象让我们可以从javascript中操作文档中的所有元素Document对象是win ...

  2. 教你记住ASP.NET WebForm页面的生命周期

    对于ASP.NET Webform的开发者,理解ASP.NET Webform的页面生命周期是非常重要的.主要是为了搞明白在哪里放置特定的方法和在何时设置各种页面属性.但是记忆和理解页面生命周期里提供 ...

  3. VS2012 直接浏览网页时报错

    VS2012 直接浏览网页时报错  "托管管道模式不能为集成" 只要在configuration文件里面添加   <system.webServer>     < ...

  4. java基础加强

    一.泛型 Generic 1.集合泛型: 在没有泛型之前,集合中存入的数据,类型就会丢失掉,在取出数据时,需要做强制类型转换,就有转换失败的风险,而这种风险,在编译阶段是没有办法检查出来的 引入泛型后 ...

  5. OC中的字符串常用方法

    OC中的字符串常用方法 OC中对字符串进行操作使用了Foundation框架中的NSString类(不可变).NSMutableString类(可变). NSString 1.创建字符串 [objc] ...

  6. javascript BOM对象 第15节

    <html> <head> <title>浏览器对象</title> <script type="text/javascript&quo ...

  7. HDU 1300 Pearls (DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1300 题目大意:珠宝店有100种不同质量的珍珠,质量越高价钱越高,为了促进销售,每买一种类型的珍珠,要 ...

  8. 【制作镜像】virsh

    首先进入到图形界面 常用virsh指令: 1)virsh list 列出当前虚拟机列表,不包括未启动的 2)virsh list --all 列出所有虚拟机,包括所有已经定义的虚拟机 3)virsh ...

  9. GIS科研站

    http://www.3sbase.com/3sbase/ 近年来,地理信息科学发展迅猛,科研人员日益增多,但目前尚缺乏良好的交流平台,致使优秀的科研成果难以推广.同时,对于大量的GIS学生而言,对国 ...

  10. Constants in C++

    The first motivation for const seems to have been to eliminate the use of preprocessor #define for v ...