移动时淡入和淡出 UIView [英] Fade in and fade out a UIView while it is moving
问题描述
动画视图很容易:
[UIView animateWithDuration:1.0
animations:^{theView.center = newCenter; theView.alpha = 0;}
completion:^(BOOL finished){
[theView removeFromSuperview];
}];
问题是,当我将其添加为子视图时,我希望它淡入并看起来像是在移动.现在它立即出现,然后移动并淡出.
The problem is that when I add it as a subview, I want it to fade in and already look like it is moving. Right now it appears immediately, then moves and fades out.
所以,我需要将它的初始 alpha 设置为零,在移动时快速淡入淡出,然后淡出.UIView 动画可以做到这一点吗?我不能让两个相互竞争的动画块在同一个对象上工作,对吗?
So, I need to set it's initial alpha to zero, fade it quickly while it is moving, then fade it out. Is this possible with UIView animations? I can't have two competing animation blocks working on the same object right?
推荐答案
您需要做的就是连续应用 2 个动画.像这样的东西::
All you need to do is apply 2 animations back-to-back. Something like this ::
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];
}];
}];
所以在第一秒它会在移动时出现,然后在下一秒它会淡出
So in the 1st second it will appear while moving and then in the next second it will fade out
希望能帮到你
这篇关于移动时淡入和淡出 UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!