Flip and turn

I have 2 views. I would like the map to be flipped and rotated on its axis to show a different view.

So when I click on view1, view1 should flip, but flip in the sense that it rotates around the y-axis to show view 2.

I'm using the FLIP directive on IOS, but that doesn't do the "twist" I'm looking for:

[UIView transitionFromView:(self.displayingPrimary ? self.primaryView : self.secondaryView)
                    toView:(self.displayingPrimary ? self.secondaryView : self.primaryView)
                  duration: 2.0
                   options: (self.displayingPrimary ? UIViewAnimationOptionTransitionFlipFromLeft :
                             UIViewAnimationOptionTransitionFlipFromRight) | UIViewAnimationOptionShowHideTransitionViews


                completion:^(BOOL finished) {
                    if (finished) {
                        self.displayingPrimary = !self.displayingPrimary;
                    }
                }];

      

+3


source to share


1 answer


There are several ways to make one flip view to another using Quartz on iOS if you don't like the built-in flip transform. The next two code snippets require you #import <QuartzCore/QuartzCore.h>

to also reference the QuartzCore structure. Note that both functions I've written assume both views are added as subzones with the same frame, and one of them is hidden ( setHidden:

).

The first function will flip one view into another using 2D transforms. It's more efficient, and all it really does is scale along the x-axis. It looks pretty good at high speeds IMO.

+ (void)flipFromView1:(UIView*)v1 toView:(UIView*)v2 duration:(NSTimeInterval)duration completion:(void (^)(BOOL finished))completion
{
    duration = duration/2;

    [v2.layer setAffineTransform:CGAffineTransformMakeScale(0, 1)];
    [UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
        [v1.layer setAffineTransform:CGAffineTransformMakeScale(0, 1)];
    } completion:^(BOOL finished){
        [v1 setHidden:YES];
        [v2 setHidden:NO];
    }];

    [UIView animateWithDuration:duration delay:duration options:UIViewAnimationOptionCurveEaseOut animations:^{
        [v2.layer setAffineTransform:CGAffineTransformMakeScale(1, 1)];
    } completion:completion];
}

      



The second function does the actual 3D transformation. Note that if rotated representations using this 3D transform are inverted or under other regions in 3D space, you can see these other views being viewed or hidden during this animation.

+ (void)flipFromView2:(UIView*)v1 toView:(UIView*)v2 duration:(NSTimeInterval)duration rToL:(BOOL)rToL completion:(void (^)(BOOL finished))completion
{
    duration = duration/2;

    v2.layer.transform = CATransform3DMakeRotation((rToL ? -1.57079633 : 1.57079633), 0, 1, 0);
    [UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
        v1.layer.transform = CATransform3DMakeRotation((rToL ? 1.57079633 : -1.57079633), 0, 1, 0);
    } completion:^(BOOL finished){
        [v1 setHidden:YES];
        [v2 setHidden:NO];
    }];

    [UIView animateWithDuration:duration delay:duration options:UIViewAnimationOptionCurveEaseOut animations:^{
        v2.layer.transform = CATransform3DMakeRotation(0, 0, 1, 0);
    } completion:completion];
}

      

+2


source







All Articles