Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 306
Mobilewits Avatar asked Oct 07 '11 19:10

Mobilewits


2 Answers

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));
like image 115
jaminguy Avatar answered Nov 17 '22 11:11

jaminguy


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."

like image 2
Jonathan Naguin Avatar answered Nov 17 '22 11:11

Jonathan Naguin