22. 延时动画的两种方式对比
// 方式1
- (void)dismissWithDelay:(NSTimeInterval)delay {
[UIView animateWithDuration:0.3
delay:delay
options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction
animations:^{
self.alpha = 0.f;
}
completion:^(BOOL finished) {
}];
}
[self dismissWithDelay:3];
NSLog(@"%f, %f, %f", self.alpha, self.layer.presentationLayer.opacity, self.layer.modelLayer.opacity); // ---> 0.000000, 1.000000, 0.000000
// 方式2
- (void)dismiss {
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction
animations:^{
self.alpha = 0.f;
}
completion:^(BOOL finished) {
}];
}
[self performSelector:@selector(dismiss) withObject:nil afterDelay:3 inModes:@[NSRunLoopCommonModes]];
NSLog(@"%f, %f, %f", self.alpha, self.layer.presentationLayer.opacity, self.layer.modelLayer.opacity); // ---> 1.000000, 1.000000, 1.000000Last updated
Was this helpful?