Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top