Basic animation, layer animation for horizontal rewind

I have two views, and I want to switch between the two views using basic animation, animating the layer of each of the views. The animation I want is similar to the one provided by UIViewAnimationOptionTransitionFlipFromLeft , but I could not do it. I could make the layer rotate 180, and then when the animation stops, I move on to the next view. How can I do that?

I used the code as shown below:

 CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"]; self.view.layer.zPosition = 100; CATransform3D transform = CATransform3DMakeRotation(M_PI, 0, 1, 0); [animation setToValue:[NSValue valueWithCATransform3D:transform]]; [animation setDuration:.5]; [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]]; [animation setFillMode:kCAFillModeForwards]; [animation setRemovedOnCompletion:YES]; [animation setDelegate:self]; [self.view.layer addAnimation:animation forKey:@"test"]; 

and in the delegate I move on to the next view. But that doesnโ€™t make much sense, and the animation is not as lively as the default animation provides. how can this be achieved?

+2
source share
2 answers

How to make it look like three-dimensional rotation

Your rotation is not like it is happening in three-dimensional space, because there is no perspective for your transformation. Change the m34 conversion value to something small, like 1.0 / 800.0, and you will see that it rotates with perspective.

 CATransform3D transform = CATransform3DMakeRotation(M_PI, 0, 1, 0); transform.m34 = 1.0/800.0; [animation setToValue:[NSValue valueWithCATransform3D:transform]]; 

This value (third column, fourth row) of the 3D transform controls the perspective of the transform. You can learn more about 3D projection on Wikipedia if you want to learn more about how this works.

How to flip two views as if they were on the sides of the map

To make it appear that two species are two sides of the same species, you must add them by turning the back side of ฯ€ degrees and changing the doubleSided layer to NO for both layers. Now they will not be visible when you are away from you. When you apply rotation on the front and back layers, they will change the appearance of the layer. Note: rotate the front ฯ€ degrees and back 2ฯ€ so that it completes the rotation and appeals to you.

+7
source

you can use

  [UIView transitionFromView:aView toView:bView duration:0.3 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) { } ]; 

I find that you want both views to be in the same super view, otherwise everything gets a little messy.

+6
source

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


All Articles