gpt4 book ai didi

ios - UIView 上的 alpha 动画不起作用

转载 作者:行者123 更新时间:2023-12-02 03:45:33 25 4
gpt4 key购买 nike

我正在制作一个自定义的segue,它会淡出为黑色,交换 View Controller ,然后淡出回透明。不幸的是,我似乎无法做到这一点。代码如下:

- (void)perform {

UIView *overlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [self.sourceViewController navigationController].view.frame.size.width, [self.sourceViewController navigationController].view.frame.size.height)];
[overlay setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.0]];
[[self.sourceViewController navigationController].view addSubview:overlay];

[UIView animateWithDuration:2.0 delay:0.0 options:(UIViewAnimationOptionCurveEaseIn) animations:^{
[overlay setAlpha:1.0];
}completion:^(BOOL finished) {
[[self.sourceViewController navigationController] pushViewController:[self destinationViewController] animated:NO];
[UIView animateWithDuration:2.0 delay:0.0 options:(UIViewAnimationOptionCurveEaseIn) animations:^{
[overlay setAlpha:0.0];
}completion:^(BOOL finished) {
[overlay removeFromSuperview];
NSLog(@"Done!");
}];
}];

}

所以,我所做的是将 UIView 添加到具有黑色背景和 alpha 为 0 的导航 Controller 。然后,我制作一个动画将 alpha 更改为 1,将目标 View Controller 推送到导航上 Controller ,然后动画回到清晰。当我这样做时,什么也没有发生。它只是将目标 View Controller 放到导航 Controller 上,没有任何类型的动画。

奇怪的是,如果我从 1 的 alpha 开始,动画到 0,然后又回到 1,它会起作用(但这不是我想要的)。

我认为发生了一些优化,排除了我清晰的 UIView,因此更改透明度是没有意义的。

最佳答案

如果你这样做会发生什么?

...
[overlay setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1.0]];
[overlay setAlpha:0.0];
[[self.sourceViewController navigationController].view addSubview:overlay];
...

关于ios - UIView 上的 alpha 动画不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15932583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com