Rotate the UIView on the X axis (horizontal axis)

I wanted to rotate the UIView on its horizontal axis 360 degrees, and then update the content in the view. I was looking for solutions about this. Found here a couple here. This is what I went out with.

[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionTransitionNone animations:^{ self.tableView.layer.transform = CATransform3DMakeRotation(M_PI,1.0,0.0,0.0); } completion:^(BOOL finished){ NSLog(@"Finished first pi"); [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionTransitionNone animations:^{ self.tableView.layer.transform = CATransform3DMakeRotation(M_PI,1.0,0.0,0.0); } completion:^(BOOL finished) { NSLog(@"Finished second pi"); }]; }]; 

This flips the view, but only 180 degrees. I want him to roll over again so that I can see the view normally.

Both of my NSLogs are displayed one by one. I'm sure something is missing here. Any help would be helpful.

thanks

+6
source share
5 answers

In your completion block, try combining the new transformation with the current transformation.

 self.tableView.layer.transform = CATransform3DConcat(self.tableView.layer.transform, CATransform3DMakeRotation(M_PI,1.0,0.0,0.0)); 
+8
source

You should check this answer. How to make CATransform3dMakeRotation rotate the other way? And the chain .

I think your problem is related to: β€œWhen you work with a transformation directly, Core Animation will interpolate the transformation from the current value to the specified transformation. It will find the shortest path for this transformation that will limit the direction of the animation. If you try to animate one and the same conversion property twice, the second value will simply override the first, and not combine the two transformations together. "

+1
source

use this: -

  rotatingView.layer.anchorPoint = CGPointMake(0.0f, 0.0f); rotatingView.center = CGPointMake(0, (rotatingView.center.y - (rotatingView.bounds.size.height/2.0f))); rotatingView.center = CGPointMake(0, (rotatingView.center.y- (rotatingView.bounds.size.height/2))); // start the Page Open [UIView beginAnimations:@"Animation" context:nil]; [UIView setAnimationDuration:13.0]; // set angle as per requirement [rotatingView.layer setValue:[NSNumber numberWithInt:280] forKeyPath:@"transform.rotation.x"]; [UIView commitAnimations]; 
+1
source

You just need to change the code from 1.0 to 0.0 inside the completion block and complete all the steps.

  [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionTransitionNone animations:^{ self.tableView.layer.transform = CATransform3DMakeRotation(M_PI,1.0,0.0,0.0); } completion:^(BOOL finished){ NSLog(@"Finished first pi"); [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionTransitionNone animations:^{ self.tableView.layer.transform = CATransform3DMakeRotation(M_PI,0.0,0.0,0.0); } completion:^(BOOL finished) { NSLog(@"Finished second pi"); }]; }]; 
0
source

You can also get closer to this using the animation options .Repeat and .Autoreverse + animation repeat value of the animation. Here is an example in Swift:

  UIView.animateWithDuration(time, delay: 0, options: [.Repeat, .Autoreverse], animations: { UIView.setAnimationRepeatCount(3) self.view.layer.transform = CATransform3DMakeRotation(CGFloat(M_PI), 1, 0, 0) }) { (completed) in // completion } 
0
source

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


All Articles