ios – 在UIView移动时淡入并淡出

前端之家收集整理的这篇文章主要介绍了ios – 在UIView移动时淡入并淡出前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
为视图设置动画很容易: @H_502_2@[UIView animateWithDuration:1.0 animations:^{theView.center = newCenter; theView.alpha = 0;} completion:^(BOOL finished){ [theView removeFromSuperview]; }];

问题是,当我将其添加为子视图时,我希望它淡入并且看起来已经移动了.现在它立刻出现,然后移动并淡出.

所以,我需要将它的初始alpha设置为零,在移动时快速淡化它,然后淡出它.这可能与UIView动画有关吗?我不能让两个竞争动画块在同一个对象上工作吗?

解决方法

您需要做的就是背靠背应用2个动画.像这样的东西:: @H_502_2@theView.alpha = 0; [UIView animateWithDuration:1.0 animations:^{ theView.center = midCenter; theView.alpha = 1; } completion:^(BOOL finished){ [UIView animateWithDuration:1.0 animations:^{ theView.center = endCenter; theView.alpha = 0; } completion:^(BOOL finished){ [theView removeFromSuperview]; }]; }];

所以在第一秒它将在移动时出现,然后在下一秒它会淡出

希望这可以帮助

猜你在找的iOS相关文章