當(dāng)我們將一個UIAlertView彈出的適合,當(dāng)點擊確定之后需要在它上面添加一個view。但是這個添加view是用的[[UIApplicationsharedApplication].keyWindowaddSubview:view];
但是這樣運行會出現(xiàn)一個問題。view出現(xiàn)一會就會消失
- (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上面的