- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self countDown:5];
}
-(void)countDown:(int)count{
if(count <0){
// do something
return;
}
NSString *string = [NSString stringWithFormat:@"%d",count];
string = count == 0 ? @"GO":string;
UILabel *timerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, kScreenHeight/2-110, kScreenWidth, 100)];
timerLabel.font = [UIFont boldSystemFontOfSize:90];
timerLabel.text = string;
timerLabel.textColor = [UIColor redColor];
timerLabel.textAlignment = NSTextAlignmentCenter;
timerLabel.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.2, 1.2);
[self.view addSubview:timerLabel];
[UIView animateWithDuration:1
delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
timerLabel.alpha = 0;
timerLabel.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.5, 0.5);
}
completion:^(BOOL finished) {
[timerLabel removeFromSuperview];
//递归调用,直到计时为零
[self countDown:count -1];
}
];
}
自定义倒计时动画
最新推荐文章于 2023-02-09 11:59:48 发布