//
// ViewController.m
// test_方法延迟调用
//
// Created by 邹彦军 on 16/7/19.
// Copyright © 2016年 邹彦军. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, strong) NSTimer* timer;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"delayMethodStart");
[self methodOnePerformSelector];
// [self methodTwoNSTimer];
// [self methodThreeSleep];
// [self methodFourGCD];
// [self methodFiveAnimation];
NSLog(@"nextMethod");
}
// 动画完成的回调
- (void)methodFiveAnimation{
[UIView animateWithDuration:0 delay:2.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
} completion:^(BOOL finished) {
[self delayMethod];
}];
}
// GCD
- (void)methodFourGCD{
__weak ViewController *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];
});
}
// 阻塞线程
- (void)methodThreeSleep{
[NSThread sleepForTimeInterval:2.0];
}
// 定时器
- (void)methodTwoNSTimer{
self.timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(delayMethod) userInfo:nil repeats:NO];
}
// performSelector方法
- (void)methodOnePerformSelector{
[self performSelector:@selector(delayMethod) withObject:nil afterDelay:2.0];
}
// 被执行的方法
- (void)delayMethod{
NSLog(@"delayMethodEnd");
}
@end