UIAlertView和UIActionSheet的IOS8兼容
来源:互联网 发布:sql语句求和1到50 编辑:程序博客网 时间:2024/06/05 17:05
IOS8中,UIActiconSheet已被废弃,同时基于UIActionSheet自定义的也将无效果。
Apple将UIActionSheet和UIAlertView整合成一个接口UIAlertController。
原来的是一个view,展示在window视图之上。现在改成了controller,展示方式变成由当前的controller直接出来。
在项目中添加以下文件,可以在兼容
UIActionSheet 兼容
.h文件
#import <UIKit/UIKit.h>#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)@interface UIActionSheet (simplyShowInViewAddition)- (void) simplyShowInView:(UIView *) view ;@end
.m文件
#import "UIActionSheet+simplyShowInViewAddition.h"@implementation UIActionSheet (simplyShowInViewAddition)- (void) simplyShowInView:(UIView *) view{ if(SYSTEM_VERSION_LESS_THAN(@"8.0")) { [self showInView:view]; } else { // "Translating" UIActionSheet to UIAlertController for better compatibility with iOS 8 UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:self.title preferredStyle:UIAlertControllerStyleActionSheet]; int nactions = [self numberOfButtons]; int i=0; while(i<nactions) { NSString *button_title=[self buttonTitleAtIndex:i]; UIAlertActionStyle style=UIAlertActionStyleDefault; if(i==[self cancelButtonIndex]) { style = UIAlertActionStyleCancel; } else if(i==[self destructiveButtonIndex]) { style = UIAlertActionStyleDestructive; } UIAlertAction *newAction = [UIAlertAction actionWithTitle:button_title style:style handler:^(UIAlertAction *action) { NSLog(@"clicked action %d",i); [self.delegate actionSheet:self clickedButtonAtIndex:i]; }]; [alert addAction:newAction]; i++; } if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { [alert setModalPresentationStyle:UIModalPresentationPopover]; UIPopoverPresentationController *popPresenter = [alert popoverPresentationController]; popPresenter.sourceView = view; popPresenter.sourceRect = CGRectMake(view.frame.size.width/2-1, 0.45*view.frame.size.height, 2, 1); popPresenter.permittedArrowDirections = 0; } UIViewController *sourceViewController; if(self.delegate!=nil && [self.delegate respondsToSelector:@selector(presentViewController:animated:completion:)]) { NSLog(@"presenting UIAlertController on source view controller"); sourceViewController=(UIViewController *)(self.delegate); } else { // When the actionsheet delegate is not a UIViewController NSLog(@"presenting UIAlertController on displayed view controller");#warning Set up a method here to obtain the view controller where you want to display it sourceViewController = /* Set up a method here to obtain the view controller where you want to display it */ } [sourceViewController presentViewController:alert animated:YES completion:nil]; }}
UIAlertView 只要对代码稍加修改就行了,就不写出了!
0 0
- UIAlertView和UIActionSheet的IOS8兼容
- UIAlertView、UIActionSheet兼容iOS8
- UIAlertView和UIActionSheet类在IOS8以后的改动
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet)
- iOS8 UIAlertView 和 UIActionSheet 的新用法 UIAlertController详解
- iOS8.0 之后UIAlertView和UIActionSheet的创建方式的新变化
- 在iOS8.0之后的UIAlertView和UIActionSheet的新写法
- iOS8.0 之后UIAlertView和UIActionSheet的创建方式的新变化
- 谈谈改变 UIAlertView 和 UIActionSheet 的颜色 iOS8及以上应该使用的方式
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- 表达式求值(中缀式转后缀式,后缀式求值)NYOJ53测试通过
- Objective-C基础笔记(1)基本概念和第一个程序
- 1004. 成绩排名 (20)
- HDU1024 Max Sum Plus Plus(DP)
- Socket 多线程通信
- UIAlertView和UIActionSheet的IOS8兼容
- Maven之——Nexus私服
- 第十一周项目4
- 多目标跟踪-Multi-Object Tracking
- FPAG学习笔记:BCD码驱动2位数码管(动态扫描)
- Oracle—decode函数行转列
- ARM开发板在WIN7系统下USB无法识别解决方案。
- gets();getschar();fget();
- 第一课 认识类与对象