这是代码
- (void)viewDidLoad {
[super viewDidLoad];
UIView *testView1 = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
UIView *testView2 = [[UIView alloc] initWithFrame:CGRectMake(100, 200, 100, 100)];
testView1.backgroundColor = [UIColor blueColor];
[self.view addSubview:testView1];
[self setView:testView1 hidden:YES];
testView2.backgroundColor = [UIColor redColor];
[self.view addSubview:testView2];
[self setView:testView2 alpha:0.f];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)setView:(UIView *)view hidden:(BOOL)hidden {
[UIView transitionWithView:view duration:1.f options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
view.hidden = hidden;
} completion:^(BOOL finished) {
[self setView:view hidden:!hidden];
}];
}
- (void)setView:(UIView *)view alpha:(CGFloat)alpha {
[UIView transitionWithView:view duration:1.f options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
view.alpha = alpha;
} completion:^(BOOL finished) {
[self setView:view alpha:1.f - alpha];
}];
}
在设备上运行代码:ios 11和ios 12 出现的动画是同步的,但是消失的动画在iOS12中是瞬时的