views:

27

answers:

1

I would like to animate my subviews movement when rotating the device, changing the alpha to 0, move the view to the new position and reset the alpha to 1.

Using this code in didRotateFromInterfaceOrientation causes the view to flash and fade very quickly and then reappear. I would like to avoid this behaviour.

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

Is there a way around this flashing?

Thanks

+1  A: 

Maybe actually animate alpha on completition ? rather than flash it ? :)

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

Cheers, Krzysztof Zabłocki

Krzysztof Zabłocki
It makes it fade nicer, but still flashes a bit suddenly. Thanks though.
joec