众所周知,当伟大的iOS7系统发布后,表扬的一堆、谩骂的也一片,而对于我们程序员来说最关心的莫过于低版本系统上的程序在搞版本系统上的兼容性问题了。

在iOS6.1几之前,当我们想要做一些提醒用户或临时获取一些数据时,通常会弹出一个模态试图,给予用户提醒,而最常见的做法莫过于直接用UIAlertView添加控件或继承UIAlertView,然后添加自己想要的控件,如:在执行网络连接  下载等耗时任务时我们会弹出一个view  然后显示一个指示器,具体做法:

- (IBAction)showTraditionAlert:(id)sender {

    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"正在下载....." message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
alertView.delegate = self;
[alertView show];
} #pragma mark -- UIAlertViewDelegate //实现代理增加网络指示器
- (void)willPresentAlertView:(UIAlertView *)alertView;{
indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
indicator.frame = CGRectMake(110, 20, 50, 50); [alertView addSubview:indicator];
[indicator startAnimating];
[indicator release];
} - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
[indicator stopAnimating];
}

但上面的做法到了iOS7上就没有用了 ,你自己所添加的控件根本显示不出来,也就是说在iOS7上不允许我们更改系统的UIAlertView了(至少目前是这样2013/07/18 beta3版本),我想大家肯定也遇到了这样的问题,那现在改怎么半呢? 可以采用UIWindow的方式实现具体做法网上很多,我比较懒 随便写了点

//
// CustomizedAlertAnimation.h
// AlertAnimationDemo
//
// Created by PSH_Chen_Tao on 7/18/13.
// Copyright (c) 2013 wolfman. All rights reserved.
// //这个类主要时用来对指定的view进行动画,,动画类似UIAlertView的出现和消失
#import <Foundation/Foundation.h> @protocol CustomizedAlertAnimationDelegate; @interface CustomizedAlertAnimation : NSObject @property(strong,nonatomic)UIView *view; @property(assign,nonatomic)id<CustomizedAlertAnimationDelegate> delegate; -(id)customizedAlertAnimationWithUIview:(UIView *)v; -(void)showAlertAnimation; -(void)dismissAlertAnimation;
@end @protocol CustomizedAlertAnimationDelegate -(void)showCustomizedAlertAnimationIsOverWithUIView:(UIView *)v; -(void)dismissCustomizedAlertAnimationIsOverWithUIView:(UIView *)v;
@end
//
// CustomizedAlertAnimation.m
// AlertAnimationDemo
//
// Created by PSH_Chen_Tao on 7/18/13.
// Copyright (c) 2013 wolfman. All rights reserved.
// #import "CustomizedAlertAnimation.h" static CGFloat kTransitionDuration = 0.3; @implementation CustomizedAlertAnimation @synthesize view; @synthesize delegate; -(void)dealloc{
if (delegate) {
delegate = nil; }
[view release];
view = nil;
[super dealloc];
} -(id)customizedAlertAnimationWithUIview:(UIView *)v{
if (self=[super init]) {
view = v; }
return self;
} //get the transform of view based on the orientation of device. -(CGAffineTransform)transformForOrientation{
CGAffineTransform transform ;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication ]statusBarOrientation]; switch (orientation) {
case UIInterfaceOrientationLandscapeLeft:
transform = CGAffineTransformMakeRotation(M_PI*1.5);
break;
case UIInterfaceOrientationLandscapeRight:
transform = CGAffineTransformMakeRotation(M_PI/2);
break;
        //这里写错了,感谢 阿秉 提出问题,当为倒置方向时才应该旋转
//case UIInterfaceOrientationPortrait:
       case UIInterfaceOrientationPortraitUpsideDown:
            transform = CGAffineTransformMakeRotation(-M_PI);
break;
default:
transform = CGAffineTransformIdentity;
break;
} return transform;
} // begin the animation -(void)showAlertAnimation{
view.transform = CGAffineTransformScale([self transformForOrientation], 0.001, 0.001);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:kTransitionDuration/1.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(firstBouncesDidStop)];
view.transform = CGAffineTransformScale([self transformForOrientation], 1.1, 1.1);
[UIView commitAnimations];
} -(void)dismissAlertAnimation{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:kTransitionDuration/2];
[UIView setAnimationDelegate:self];
view.alpha = 0;
[UIView setAnimationDidStopSelector:@selector(dismissAlertAnimationDidStoped)];
[UIView commitAnimations];
} #pragma mark -- UIViewAnimation delegate -(void)firstBouncesDidStop{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:kTransitionDuration/2];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(secondBouncesDidStop)];
view.transform = CGAffineTransformScale([self transformForOrientation], 0.9, 0.9);
[UIView commitAnimations]; } -(void)secondBouncesDidStop{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:kTransitionDuration/2];
view.transform = [self transformForOrientation];
[UIView commitAnimations]; //You can do somethings at the end of animation [self.delegate showCustomizedAlertAnimationIsOverWithUIView:view];
} -(void)dismissAlertAnimationDidStoped{
[self.delegate dismissCustomizedAlertAnimationIsOverWithUIView:view];
}
@end
//
// ;
// AlertDemo
//
// Created by PSH_Chen_Tao on 7/19/13.
// Copyright (c) 2013 wolfman. All rights reserved.
// //自定义的 alert view 类 #import <Foundation/Foundation.h> #import "CustomizedAlertAnimation.h" @protocol CustomeAlertViewDelegate ; @interface CustomeAlertView : UIWindow <CustomizedAlertAnimationDelegate> @property(strong,nonatomic)UIView *myView; @property(strong,nonatomic)UIActivityIndicatorView *activityIndicator; @property(strong,nonatomic)CustomizedAlertAnimation *animation; @property(assign,nonatomic)id<CustomeAlertViewDelegate> delegate;
-(void)show;
@end @protocol CustomeAlertViewDelegate -(void)CustomeAlertViewDismiss:(CustomeAlertView *) alertView; @end
//
// CustomeAlertView.m
// AlertDemo
//
// Created by PSH_Chen_Tao on 7/19/13.
// Copyright (c) 2013 wolfman. All rights reserved.
// #import "CustomeAlertView.h" @implementation CustomeAlertView
@synthesize myView;
@synthesize activityIndicator;
@synthesize animation;
@synthesize delegate;
-(id)init{
if (self=[super init]) {
self.frame = [[UIScreen mainScreen] bounds];
self.backgroundColor = [UIColor clearColor];
//UIWindow的层级 总共有三种
self.windowLevel = UIWindowLevelAlert;
myView = [[UIView alloc]initWithFrame:CGRectMake(30, 140, 260, 200)];
UIButton *okButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[okButton setBackgroundImage:[UIImage imageNamed:@"alert-view-ok-button"] forState:UIControlStateNormal];
[okButton addTarget:self action:@selector(pressoKButton:) forControlEvents:UIControlEventTouchUpInside];
okButton.frame = CGRectMake(90, 130, 80, 40);
[myView addSubview:okButton];
// [okButton release]; activityIndicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(105, 75, 50, 50)];
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
[myView addSubview:activityIndicator];
// [activityIndicator release];
UIImageView *imageView = [[UIImageView alloc]initWithFrame:myView.bounds];
[imageView setImage:[[UIImage imageNamed:@"alert-view-bg-portrait"] stretchableImageWithLeftCapWidth:100 topCapHeight:30]];
[myView insertSubview:imageView atIndex:0];
[imageView release]; animation = [[CustomizedAlertAnimation alloc]customizedAlertAnimationWithUIview:myView];
animation.delegate = self;
[self addSubview:myView];
[myView release];
} return self;
} -(void)show{
[self makeKeyAndVisible];
[animation showAlertAnimation];
} -(void)dismiss{ [self resignKeyWindow];
[animation dismissAlertAnimation]; } -(void) pressoKButton:(id)sender{
[self dismiss];
} #pragma mark -- CustomizedAlertAnimationDelegate //自定义的alert view出现动画结束后调用
-(void)showCustomizedAlertAnimationIsOverWithUIView:(UIView *)v{
NSLog(@"showCustomizedAlertAnimationIsOverWithUIView");
[activityIndicator startAnimating];
} //自定义的alert view消失动画结束后调用
-(void)dismissCustomizedAlertAnimationIsOverWithUIView:(UIView *)v{
NSLog(@"dismissCustomizedAlertAnimationIsOverWithUIView");
[activityIndicator stopAnimating]; [self.delegate CustomeAlertViewDismiss:self]; } @end
//
// ViewController.h
// AlertDemo
//
// Created by PSH_Chen_Tao on 7/19/13.
// Copyright (c) 2013 wolfman. All rights reserved.
// #import <UIKit/UIKit.h> #import "CustomeAlertView.h"
@interface ViewController : UIViewController <UIAlertViewDelegate,CustomeAlertViewDelegate>
- (IBAction)showTraditionAlert:(id)sender;
- (IBAction)showWindowAlert:(id)sender; @property(strong,nonatomic) UIActivityIndicatorView *indicator; @property(strong,nonatomic)CustomeAlertView *customeAlertView;
@end
//
// ViewController.m
// AlertDemo
//
// Created by PSH_Chen_Tao on 7/19/13.
// Copyright (c) 2013 wolfman. All rights reserved.
// #import "ViewController.h" @interface ViewController () @end @implementation ViewController @synthesize indicator; @synthesize customeAlertView; - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} - (IBAction)showTraditionAlert:(id)sender { UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"正在下载....." message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
alertView.delegate = self;
[alertView show];
} - (IBAction)showWindowAlert:(id)sender { customeAlertView = [[CustomeAlertView alloc]init];
customeAlertView.delegate = self; [customeAlertView show];
} #pragma mark -- UIAlertViewDelegate //实现代理增加网络指示器
- (void)willPresentAlertView:(UIAlertView *)alertView;{
indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
indicator.frame = CGRectMake(, , , ); [alertView addSubview:indicator];
[indicator startAnimating];
[indicator release];
} - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
[indicator stopAnimating];
} #pragma mark -- CustomeAlertViewDelegate -(void)CustomeAlertViewDismiss:(CustomeAlertView *) alertView{
[alertView release]; NSLog(@"CustomeAlertViewDismiss");
}
@end

对于UIWindow的相关东西可以参考  http://www.cnblogs.com/smileEvday/archive/2012/03/27/2420362.html#2728097

注意设计到UIWindow显示的工程不能用arc ,具体原因还没找到让我信服的 ,希望知道的大牛可以回复下。。。。。。。

自定义的UIAlertView不能在iOS7上正常显示的更多相关文章

  1. IOS 7 自定义的UIAlertView不能在iOS7上正常显示

    本文转载至 http://blog.csdn.net/hanbing861210/article/details/13614405 众所周知,当伟大的iOS7系统发布后,表扬的一堆.谩骂的也一片,而对 ...

  2. 自定义plain 样式的 tableview,模拟器上不显示分割线,真机上却显示分割线.

    一, 经历 1> 自定义plain 样式的 tableview,模拟器上不显示分割线,真机上却显示cell 下面的分割线. 2> 尝试使用表格的separatorStyle属性,尝试失败. ...

  3. iOS7上leftBarButtonItem无法实现滑动返回的完美解决方案

    今天遇到了在iOS7上使用leftBarButtonItem却无法响应滑动返回事件的问题,一番谷歌,最后终于解决了,在这里把解决方案分享给大家. 在iOS7之前的系统,如果要自定义返回按钮,直接设置b ...

  4. iOS7上的地图定位接口BUG

    遇到个BUG,卡了好久,就是在iOS9上定位接口是正常的,但是在iOS7上就一直拿不到回调,但是看系统日志其实已经定位到了.总是在报一句not response,也没有具体函数名 昨天灵机一动,从de ...

  5. ios7 上 UIActivity 用的image

    在ios8 上UIActivityCategoryShare类型的UIActivity的图标支持彩色图片了,但是在ios7上不行,ios8上的 UIActivityCategoryAction类型也不 ...

  6. iOS7上TableViewCell的button和UIImageView个别未显示的bug

    要做这个cell,用xib将cell做成之后,在iPhone6.6Plus.5s上运行良好,但是在iOS7的5s和iPad上,黄色的小星星和下载按钮均没有显示. 甚为惊奇. 在网上百度之,发现了解决办 ...

  7. phpcms v9自定义表单提交后返回上一页实现方法

    PHPcms v9中提交自定义表单后默认都是回到首页的,是不是感觉很不爽! 接下来,就说下phpcms v9自定义表单提交后返回上一页实现方法. 1.找到这个文件 phpcms\modules\for ...

  8. IOS7上呈现IOS6的水滴刷新效果

    IOS7上呈现IOS6的水滴刷新效果    到了IOS7 发现自带的刷新 不再是 IOS6自带的水滴效果了 你是否怀念那IOS6的效果呢? 哈哈,于是收集各方资料,整理编写一个属于自己的水滴刷新效果 ...

  9. ios7上隐藏status bar

    在iOS7上 对于设置status bar 又有了点点的改变 1.对于 UIViewController 加入了动态改变 status bar style的方法 - (UIStatusBarStyle ...

随机推荐

  1. R.layout.main connot be resolved 和R.java消失

    出现例如以下问题: 鼠标放到出代码上面: 分析问题: 1.查看R文件是否被生成.假设没有生成,则勾选build Automatically,然后Clean: 2.假设R文件已生成.则删除去掉代码中: ...

  2. Java初认识--Java语言的书写规范及基本的运算符

    一.Java中名称的规范和书写程序的规范. 1.Java中的名称规范: (1)包名全是小写:xxyyzz: (2)类名接口名:首字母大写:XxxYyy: (3)变量名和函数名:变量名不能是关键字:多单 ...

  3. 深入struts2(三)---工作机制和运行流程图

    1     工作原理 1.1     体系架构 图2.1 struts2.0体系架构图 1.2     工作机制 针对上节体系架构图,以下分步说明运行流程 Ø  client初始化一个指向Servle ...

  4. Math.random引发的骗术,绝对是用随机数骗前端妹纸的最佳方法

    我觉得今天我运气特好,今天我们来赌一赌,我们来搞个随机数,Math.floor(Math.random() * 10),如果这个数等于0到7,这个月的饭,我全请了,如果是8或9,你就请一个礼拜成不?于 ...

  5. 深入了解 Java HelloWorld

    Java 的 Hello World 代码 public class HelloWorld { /** * * @param args */ public static void main(Strin ...

  6. 让Xcode Lua 语法高亮

    本人不太喜欢用code ide 还是喜欢XCODE的风格 1.让Xcode支援Lua语法高亮(Syntax Highlighting) 1. 下载https://github.com/breinhar ...

  7. Dev环境中的集成测试用例执行时上下文环境检查(实战)

    Dev环境中的集成测试用例执行时上下文环境检查(实战) Microsoft.NET 解决方案,项目开发必知必会. 从这篇文章开始我将分享一系列我认为在实际工作中很有必要的一些.NET项目开发的核心技术 ...

  8. 谈一谈struts2和springmvc的拦截器

    最近涉及到了两个项目,都需要考虑全局的拦截器,其功能就是判断session的登陆状态,如果session信息完好,可以从中取得相应的信息,则放行,否则拦截,进入重定向的uri. 既然是全局的拦截器,其 ...

  9. Mysql基础之字符集与乱码

    原文:Mysql基础之字符集与乱码 Mysql的字符集设置非常灵活 可以设置服务器默认字符集 数据库默认字符集 表默认字符集 列字符集 如果某一个级别没有指定字符集,则继承上一级. 以表声明utf8为 ...

  10. .NET MVC4 实训记录之一(引入Unity3.0 Ioc框架)

    一直在做维护项目,没有机会接触完整的架构,于是自学.NET MVC.自今日起,将自学的过程.遇到的问题以及解决方案记录下来. 在WebApp项目中右键,使用NuGet引入Unity3.0.