iOS8新特性(1)——UIAlertController
2015-08-30 10:55
274 查看
一、iOS8介绍
iOS8 新特性,主要是UI上进行了统一
1、UIAlertController
2、UIPresentaionController:管理所有通过modal出来的控制器(看笔记)
3、UIPopoverPresentationController
4、SizeClass + Autolayout
5、App Extension 应用扩展
6、Core Image(iOS 5开始就有了,滤镜美图秀秀型 )
二、UIAlertController
1、以往我们使用的时候,都是用的 UIAlertView和UIActionSheet
2、而从iOS8开始, UIAlertController = UIAlertView + UIAlertSheet
3、在iPhone和iPad中同时适用的方式
注意:
UIAlertControllerStyleActionSheet
1、不能有文本框
2、在iPad中,必须使用popover的形式展示
iOS8 新特性,主要是UI上进行了统一
1、UIAlertController
2、UIPresentaionController:管理所有通过modal出来的控制器(看笔记)
3、UIPopoverPresentationController
4、SizeClass + Autolayout
5、App Extension 应用扩展
6、Core Image(iOS 5开始就有了,滤镜美图秀秀型 )
二、UIAlertController
1、以往我们使用的时候,都是用的 UIAlertView和UIActionSheet
//选项弹出等 -(void)alertViewOld { UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"111" message:@"222" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;//4种方式 [alert show]; //如果要监听点击事件则需要去设置对应的代理,并在代理方法中操作 } //底部弹出 -(void)aletSheetOld { UIActionSheet *action = [[UIActionSheet alloc]initWithTitle:@"111" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"犹豫" otherButtonTitles:@"确定", nil]; [action showInView:self.view]; }
2、而从iOS8开始, UIAlertController = UIAlertView + UIAlertSheet
#pragma mark -- new iOS8 -(void)new { //1、创建中间的弹出:UIAlertView UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"标题" message:@"弹出信息" preferredStyle:UIAlertControllerStyleAlert]; //创建底部的弹出:UIAlertSheet //UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"标题" message:@"弹出信息" preferredStyle:UIAlertControllerStyleActionSheet]; //2、添加按钮(不需要代理了) //这里需要防止循环引用(可以通过新建一个自己的控制器继承UIAlertController,在dealloc中打印信息,验证是否有最终释放) __weak typeof(alert) weakAlert = alert; [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { NSLog(@"%@",[weakAlert.textFields.firstObject text]); }]]; [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]]; [alert addAction:[UIAlertAction actionWithTitle:@"默认" style:UIAlertActionStyleDefault handler:nil]]; //3、添加文本框(只能是添加到UIAlertControllerStyleAlert的样式,如果是preferredStyle:UIAlertControllerStyleActionSheet的话会崩溃的) [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.textColor =[UIColor redColor]; textField.text = @"11111"; //监听文字的改变(如果是用通知的话,移除的时机需要注意,点击确定或者取消的时候就需要去移除,比较麻烦) [textField addTarget:self action:@selector(textFieldsValueDidChange:) forControlEvents:UIControlEventEditingChanged]; }]; [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.secureTextEntry = YES; textField.text = @"22222"; }]; //4、弹出控制器,要想是不是用modal [self presentViewController:alert animated:YES completion:nil]; } -(void)textFieldsValueDidChange:(UITextField *)textField { NSLog(@"%@",textField.text); }
3、在iPhone和iPad中同时适用的方式
#pragma mark -- new iOS8 in iPad /** * 注意: UIAlertControllerStyleActionSheet 1、不能有文本框 2、在iPad中,必须使用popover的形式展示 以后都是用present */ -(void)newInpad { //1、创建底部的弹出:UIAlertSheet UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"标题" message:@"弹出信息" preferredStyle:UIAlertControllerStyleActionSheet]; // 1.1 这句代码可写可不写,因为默认就会以UIModalPresentationPopover的形式存在 alert.modalPresentationStyle = UIModalPresentationPopover; // 1.2 设置popover指向按钮(这句代码iPhone中会被忽略,iPad中才会实现) alert.popoverPresentationController.barButtonItem = self.navigationItem.leftBarButtonItem; //2、添加按钮(不需要代理了) //这里需要防止循环引用(可以通过新建一个自己的控制器继承UIAlertController,在dealloc中打印信息,验证是否有最终释放) __weak typeof(alert) weakAlert = alert; [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { NSLog(@"%@",[weakAlert.textFields.firstObject text]); }]]; [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]]; [alert addAction:[UIAlertAction actionWithTitle:@"默认" style:UIAlertActionStyleDefault handler:nil]]; //4、弹出控制器,要想是不是用modal [self presentViewController:alert animated:YES completion:nil]; }
注意:
UIAlertControllerStyleActionSheet
1、不能有文本框
2、在iPad中,必须使用popover的形式展示
相关文章推荐
- 编写广播时出现Exported receiver does not require permission
- 学习YUI.Ext 第一天:EXT简介(一)
- HOWTO: Install, Build and Use openCV (MacOSX 10.10)
- POJ 2524 Ubiquitous Religions(宗教种类:并差集)
- adbd cannot run as root in production builds
- iphone开发之表格组件UITableView的使用(一)使用时的具体步骤介绍
- UUID.randomUUID().toString 简单解释
- CodeForces 441A Valera and Antique Items
- iOS开发 - UICollectionViewLayout 自定义布局
- iOS开发 - UICollectionViewFlowLayout 流水布局
- UIday02~04:UITextField UIButton UIdelegate 自定义视图 容器视图控制器
- POJ 3458 && HDU 1683 Colour Sequence(水~)
- Win10 Build 10532语言包官方下载地址汇总
- POJ 3094 && HDU 2734 Quicksum(水~)
- esayyui的layout嵌套布局可以解决fit自适应的位置偏移问题
- HDU1005 - Number Sequence (矩阵快速幂)
- Arduino CNC Shiled 和 DRV8825驱动板的注意事项
- UICollectionView
- Arduino 3G shield using SoftwareSerial to control
- iOS开发UI篇—字典转模型