Chris
Chris

Reputation: 242

UIViewAnimation: Blocked-based not working. Deprecated style works?

There are two main documented methods of animating UIViews. One, is a deprecated process in which one makes multiple calls beginning with method beginAnimations:context: and the other, newer, suggested approach is block-based.

I have the following code in my application. However, only the older deprecated animation segment works. The newer, block-based approach works the first time, but every subsequent time skips directly to the end of the animation and shows me only the final frame immediately. Has anybody had any experienced with this?

-(void)updateImageViewSlider:(UIImage *)image {

    mImageFeedSwipe.alpha = 0.0;
    [mImageFeedSwipe setHidden:NO];
    mImageFeedSwipe.frame = DEFAULT_IMAGEVIEW_RECT;

    [mImageFeedSwipe setImage:image];

    //
    // The following animation code works fine.
    //

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    mImageFeedSwipe.alpha = 1.0;
    [mImageFeedSwipe setFrame:NEW_IMAGEVIEW_RECT];
    [UIView commitAnimations];

    //
    // The following DOES NOT work except on the first run
    //

    int animationOptions = 0
    | UIViewAnimationOptionCurveEaseInOut
    | UIViewAnimationOptionBeginFromCurrentState
    | UIViewAnimationOptionAllowUserInteraction;
    [UIView animateWithDuration:1.0
                          delay:0 
                        options:animationOptions
                     animations:^{  

                         // Bring in the swiping image view...
                         mImageFeedSwipe.alpha = 1.0;
                         [mImageFeedSwipe setFrame:NEW_IMAGEVIEW_RECT];
                        } 
                     completion:nil];
}

This is being run on the main thread via [self performSelectorOnMainThread...].

Upvotes: 1

Views: 269

Answers (1)

Brian Moncur
Brian Moncur

Reputation: 101

I was seeing this same problem until I realized that in between animations I was hiding the view and never changing view.hidden to NO again. Any chance that you are hiding your view or setting alpha to 0.0 in between animations?

Upvotes: 1

Related Questions