首页 > 解决方案 > UIView 隐藏动画在 iOS 12 中不起作用

问题描述

这是代码

- (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];
    }];
}

在 device:ios 11 和 ios 12 运行代码 出现的动画是同步的,但是在 iOS12 中消失的动画是瞬时的

在此处输入图像描述

在此处输入图像描述

标签: iosobjective-cios12ios-animations

解决方案


推荐阅读