Rotate a UIView on its X-axis(Horizontal axis)

10,696

Solution 1

In your completion block try concatenating the new transform with the current transform.

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

Solution 2

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

I think that your problem is related with: "When you are working with a transform directly, Core Animation will interpolate the transform from the current value to the specified transform. It will find the shortest path to get to that transform, which will restrict the animation direction. If you try to animate the same transform property twice, the second value will simply override the first, not combine the two transforms together."

Solution 3

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];
Share:
10,696
Mobilewits
Author by

Mobilewits

-

Updated on June 14, 2022

Comments

  • Mobilewits
    Mobilewits almost 2 years

    I wanted to rotate a UIView on its horizontal axis for 360 degrees and then refresh the content in the view. I was looking out for solutions on this. Found a couple here n there. This is what I came 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 by 180 degrees. I want it to flip one more time so that I can see the view normally..

    Both my NSLogs are displayed one after the other. I am sure I am missing something here. ANy help would be helpful..

    Thanks

  • Jacob Relkin
    Jacob Relkin over 12 years
    You don't need to set the transform on the CALayer directly in this case, you can simply set the transform on the UIView, although it is a different struct type - a CGAffineTransform.
  • jaminguy
    jaminguy over 12 years
    That's correct. I just wanted to go off of the example given. I always use the transform on UIView.