Using the block completion handler in iOS 4 for animation

I would like to animate the movement of my view as the device rotates, changing alpha to 0, moving the view to a new position and reset alpha-1.

Using this code in didRotateFromInterfaceOrientationcauses the view to flash and quickly disappear, and then reappears. I would like to avoid this.

[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 to blink?

thank

+3
source share
1 answer

Maybe the alpha animation is actually at the end? and not flash? :)

[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 Zablotsky

+4
source

Source: https://habr.com/ru/post/1768216/


All Articles