Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Block Completion Handler in iOS 4 for animation

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

like image 674
joec Avatar asked Jan 27 '26 06:01

joec


1 Answers

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

like image 94
Krzysztof Zabłocki Avatar answered Jan 29 '26 18:01

Krzysztof Zabłocki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!