Eyal
Eyal

Reputation: 10828

How to do UIView nonstop flip animation

I want to get an effect of a UIView doing 360 degree rotation around the Y axis without stopping.

Upvotes: 0

Views: 621

Answers (1)

joerick
joerick

Reputation: 16458

Put the following code in your view controller:

CATransform3D t3d = CATransform3DIdentity;
// m34 sets the amount of perspective
t3d.m34 = 1.0/-1000.0;

[UIView animateWithDuration:1.0 
                      delay:0.0 
                    options:UIViewAnimationCurveLinear 
                 animations:^{
                     self.view.layer.transform = CATransform3DRotate(t3d, M_PI, 0, 1, 0);
                 } 
                 completion:^(BOOL finished) {
                     [UIView animateWithDuration:1.0 
                                           delay:0.0 
                                         options:UIViewAnimationCurveLinear 
                                      animations:^{
                                          self.view.layer.transform = CATransform3DRotate(t3d, 2*M_PI, 0, 1, 0);
                                      } 
                                      completion:^(BOOL finished) {
                                          self.view.layer.transform = CATransform3DIdentity;
                                      }];
                 }];

It's pretty messy, if anybody has any suggestions on how to clear this up, let me know ;)

Upvotes: 1

Related Questions