动画UIView alpha的问题 [英] Problems animating UIView alpha

查看:261
本文介绍了动画UIView alpha的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将淡入淡出应用于我在另一个上面以编程方式创建的UIView。

I'm trying to apply a fade to an UIView I created programmatically on the top of another.

[UIView animateWithDuration:0.5 animations:^(void) {
    [self.view setAlpha:0];
}
                 completion:^(BOOL finished){
                     [self.view removeFromSuperview];
                 }];

完成的事件在0.5秒后正确调用,但我看不到任何淡入淡出(I应该看到底部的UIView。)

The finished event is called properly after exactly 0.5 seconds, but I don't see any fade (I should see the UIView on the bottom).

如果不是使用alpha,我会移开UIView它可以工作(我看到底部的UIView,而顶部的UIView滑开了),所以它似乎是一个与alpha有关的问题,但我无法弄清楚出了什么问题!

If instead of using the alpha, I move away the UIView it works (I see the bottom UIView while the top UIView slides away), so it seems to be a problem related to alpha, but I can't figure out what's wrong!

[UIView animateWithDuration:0.5 animations:^(void) {
    CGRect o = self.view.frame;
    o.origin.x = 320;
    self.view.frame = o;
}
                 completion:^(BOOL finished){
                     [self.view removeFromSuperview];
                 }];

我之前使用过alpha动画,它们通常以这种方式工作......

I used alpha animations previously and they works in this way usually...

推荐答案

尝试将 opaque 设置为明确。我有同样的问题和设置解决了我的问题。显然,不透明的观点似乎与alpha不相符。

Try setting opaque to NO explicitly. I had the same problem and setting that solved my problem. Apparently, opaque views just don't seem to play well with alpha.

但是归功于Hampus Nilsson的评论。

Credit goes to Hampus Nilsson's comment though.

这篇关于动画UIView alpha的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆