开发者

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

开发者 https://www.devze.com 2023-03-24 04:59 出处:网络
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, suggeste

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...].


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号