加在window上的view 出现一闪而过的情况

加在window上的view 出现一闪而过的情况

主要是因为界面上也添加了UIAlertView

在UIAlterView的代理方法中 -(void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

 添加一个UIView到[[UIApplication sharedApplication].keyWindow上,却只出现了0.5秒左右就消失

在这里,我们需要注意,

在有UIAlertView的地方,通过 [UIApplication sharedApplication].keyWindow 获取到的窗口是alertView的,因为他的级别最高(霸屏),所以这里,只要alertView消失的时候,你添加到window的view也会一起跟着消失了。

在这里解决办法可以做一个延时,alertView消失0.5秒后,创建view,add view,注意延时的时间要大于0.5秒。

-(void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

        [self downloadFileWithUrl:self.currWineClassInfo.fileUrl];

        [self performSelector:@selector(delayView) withObject:nil afterDelay:0.6];

    }

}

-(void)delayView {

UIView *v = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];  

v.backgroundColor = [UIColor redColor];  

[[UIApplication sharedApplication].keyWindow addSubview:v];  

}

原文地址:https://www.cnblogs.com/wuxiufang/p/8796018.html