Best way to transition between two images in a UIImageView

后端 未结 7 2351
無奈伤痛
無奈伤痛 2020-12-13 00:01

I have implemented a pretty simple picture viewer that will allow the user to browse through a collection of images. They are loaded from the Internet, and displayed on the

7条回答
  •  没有蜡笔的小新
    2020-12-13 00:17

    Nothing different from what's been explained but in code, these are the available transitions:

    typedef enum {
            UIViewAnimationTransitionNone,
            UIViewAnimationTransitionFlipFromLeft,
            UIViewAnimationTransitionFlipFromRight,
            UIViewAnimationTransitionCurlUp,
            UIViewAnimationTransitionCurlDown,
        } UIViewAnimationTransition;
    

    Code (Put this in a callback like touchesEnded):

    CGContextRef context = UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];
    
    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:[self superview] cache:YES];
    
    // -- These don't work on the simulator and the curl up will turn into a fade -- //
    //[UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView:[self superview] cache:YES];
    //[UIView setAnimationTransition: UIViewAnimationTransitionCurlDown forView:[self superview] cache:YES];
    
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:1.0];
    
    // Below assumes you have two subviews that you're trying to transition between
    [[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
    [UIView commitAnimations];
    

提交回复
热议问题