当我们将一个UIAlertView弹出的适合,当点击确定之后需要在它上面添加一个view。但是这个添加view是用的[[UIApplicationsharedApplication].keyWindowaddSubview:view];
但是这样运行会出现一个问题。view出现一会就会消失
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex==1) {
UIView*view=[[UIViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
view.backgroundColor=[UIColorredColor];
[[UIApplicationsharedApplication].keyWindowaddSubview:view];
}
}
如果换一种方法 延迟0.6秒就可以了
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex==1) {
//UIAlertView是增加到window上面的需要等到UIAlertView删除之后再加到window上面
[selfperformSelector:@selector(delayView)withObject:nilafterDelay:0.6];
}
}
-(void)delayView{
UIView*view=[[UIViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
view.backgroundColor=[UIColorredColor];
[[UIApplicationsharedApplication].keyWindowaddSubview:view];
}
这是因为UIAlertView是加到Window上面的