UIView animation animation with active animation

Dear Core Animation / iOS experts,

I am trying to get an effect similar to the question below.

Basic animation, layer animation for horizontal movement

The accepted answer seems to accurately describe what I need, except for the code with this answer, and I cannot get the code that I write to work.

Here is what I am trying to do:
1) Have 1 controller / view of the main controller and on the main view part there are 2 UIViews that overlap, only one is shown (1 on the "front" and 1 on the "back")
2) A separate UIControl / UIButton is pressed, and then there is a transition of the 3D transition, which rotates the front (visible) view out of sight and at the same time rotates the back (hidden) front view ... just like seeing a reverse playing card.
3) Hold down the UIControl button to switch between the two viewing modes 4) Only be able to interact with the controls on the front panel (i.e., pressing the front layer will not inadvertently work on the rear panel, which is located under the tap)

Perhaps I am approaching this wrong, so let me know. Ideally, I would like to use Core Animation rather than the UIView built into the flip transaction, as I want the animation to be 3D, and also want to use this task as a step to create more complex CA material.

At the moment, I can get a front view to switch well (only once), but the rear view is not displayed.

Cheers
Andy

Here is the code I have:

MainViewController.h

@interface MainViewController : UIViewController - (IBAction)changeViewTapped:(UITapGestureRecognizer *)recognizer; @end 

MainViewController.m

 #import "MainViewController.h" #import <QuartzCore/QuartzCore.h> @interface MainViewController () @property (weak, nonatomic) IBOutlet UIView *detailView; @property (weak, nonatomic) IBOutlet UIView *listView; @property (nonatomic) CATransform3D rotationAndPerspectiveTransform; @end @implementation MainViewController @synthesize detailView = _detailView; @synthesize listView = _listView; @synthesize rotationAndPerspectiveTransform = _rotationAndPerspectiveTransform; - (void)viewDidLoad { [super viewDidLoad]; CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity; rotationAndPerspectiveTransform.m34 = 1.0 / -500; rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, M_PI, 0.0f, 1.0f, 0.0f); self.rotationAndPerspectiveTransform = rotationAndPerspectiveTransform; CALayer *listLayer = self.listView.layer; listLayer.doubleSided = NO; listLayer.transform = self.rotationAndPerspectiveTransform; } - (IBAction)changeViewTapped:(UITapGestureRecognizer *)recognizer { CALayer *detailLayer = self.detailView.layer; CALayer *listLayer = self.listView.layer; detailLayer.doubleSided = NO; listLayer.doubleSided = NO; [UIView animateWithDuration:0.5 animations:^{ detailLayer.transform = self.rotationAndPerspectiveTransform; listLayer.transform = self.rotationAndPerspectiveTransform; } completion:^(BOOL finished){ // code to be executed when flip is completed }]; } @end 
+4
source share
2 answers

Quick tip on flip animation in iOS - the system takes time to render the rear view (the one that will be flipped) before you start the flipping animation. Therefore, if you try to change the contents of this view and activate flip animation in the same method, you will have problems.

To get around this, I had success with code like this:

 - (void)flipView { // Setup the view for the back side of the flip [self performSelector:@selector(performFlip) withObject:nil afterDelay: 0.1]; } - (void)performFlip { [UIView transitionWithView: tileToFlip duration: 0.5 options: UIViewAnimationOptionTransitionFlipFromLeft animations:^{ // My flip specific code } completion:^(BOOL finished) { } ]; } 

In short, I set everything up in the flipView method, returning iOS control so that it has time to render it, and then let go of the flipTile selector flipTile a tenth of a second to complete the actual animation.

Good luck

+3
source
 - (void)perform { UIViewController *src = (UIViewController *) self.sourceViewController; UIViewController *dst = (UIViewController *) self.destinationViewController; [UIView beginAnimations:@"LeftFlip" context:nil]; [UIView setAnimationDuration:0.8]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:src.view.superview cache:YES]; [UIView commitAnimations]; [src presentViewController:dst animated:NO completion:nil]; } 
0
source

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


All Articles