在UIWindow上展示/移除一个View
UIWindow *window = [[UIApplication sharedApplication].windows lastObject];//添加view
[[[UIApplication sharedApplication].keyWindow viewWithTag:888] removeFromSuperview];//移除指定view
UIView显示在最上面/最下面
-(void)bringSubviewToFront:(UIView *)view;//将UIView显示在最前面
-(void)sendSubviewToBack:(UIView *)view;//将UIView显示在下面
实现延迟执行的方法
1. performSelector(非阻塞执行)
[self performSelector:@selector(delayMethod) withObject:nil/*可传任意类型参数*/ afterDelay:2.0];
2.NSTimer定时器(非阻塞执行)
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector() userInfo:nil repeats:YES];
取消执行方法:- (void)invalidate
3.:NSThread线程的sleep(阻塞执行)
[NSThread sleepForTimeInterval:2.0];//后面的程序会在2秒后执行
4.GCD延迟执行(非阻塞执行,可选择对应的线程执行)
__block self/*主控制器*/ *weakSelf = self;
dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0/*延迟执行时间*/ * NSEC_PER_SEC));
dispatch_after(delayTime, dispatch_get_main_queue(), ^{
[weakSelf delayMethod];
});
待续继续整理
网友评论