在iOS 4中使用块完成处理程序进行动画处理

时间:2010-10-06 11:39:32

标签: objective-c animation ios4 block

我想在旋转设备时动画我的子视图移动,将alpha更改为0,将视图移动到新位置并将alpha重置为1.

didRotateFromInterfaceOrientation中使用此代码会导致视图快速闪烁并淡出,然后重新出现。我想避免这种行为。

[UIView animateWithDuration:kAnimationDuration animations:^{
    anObject.alpha = 0.0;
    CGRect newFrame = anObject.frame;
    newFrame.origin.x = newX;
    newFrame.origin.y = newY;
    newFrame.size.width = newWidth;
    newFrame.size.height = newHeight;
    anObject.frame = newFrame;
} completion:^ (BOOL finished){
    if (finished) {
        anObject.alpha = 1.0;
    }
}];

有没有办法解决这种闪烁问题?

由于

1 个答案:

答案 0 :(得分:4)

也许在完成时实际上是动画alpha?而不是闪光吗? :)

[UIView animateWithDuration:kAnimationDuration animations:^{
anObject.alpha = 0.0;
CGRect newFrame = anObject.frame;
newFrame.origin.x = newX;
newFrame.origin.y = newY;
newFrame.size.width = newWidth;
newFrame.size.height = newHeight;
anObject.frame = newFrame;
} completion:^ (BOOL finished){
if (finished) {
[UIView animateWithDuration:kAnimationDuration
                                 animations:^{
                                     anObject.alpha = 1;} 
} 
}];

干杯, KrzysztofZabłocki