2010-10-06 60 views
3

我想旋转设备时,改变的α为0,以动画我的子视图的运动,移动视图到新的位置和α复位到1。在IOS 4使用块完成处理程序的动画

使用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; 
    } 
}]; 

有没有办法解决这个问题?

谢谢

回答

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;} 
} 
}]; 

干杯, 克日什托夫·Zabłocki

+0

它使褪色更好,但仍然闪烁有点突然。不过谢谢。 – joec 2010-10-06 15:08:33