2013-03-07 168 views
0

我有一个UIImageView与旋转动画循环,我需要在屏幕上移动X和Y的UIImageView。移动和旋转UIImageView

旋转动画代码:

-(void)rotate{ 

if (leftRotate){ 
    leftRotate = NO; 
}else{ 
    leftRotate = YES; 
} 

CGRect initFrame = self.frame; 

[UIView animateWithDuration:0.5 
         delay:0.0 
        options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse 
       animations:^{ 

        if (leftRotate){ 
         self.transform = CGAffineTransformRotate(self.transform, -1 * (M_PI/8)); 
        }else{ 
         self.transform = CGAffineTransformRotate(self.transform, M_PI/8); 
        } 

       } 
       completion:^(BOOL completed) { 
        if (completed){ 
         if (!stopRotate){ 
          [self rotate]; 
         } 
        } 
       }]; 
} 

我试着型动物的方法来移动图像,如设置中心,但我不能移动它。

+0

你也可以使用一个CGAffineTransformConcat到CGAffineTransformRotate和CGAffineTransformTranslate合并成一个转换并应用 – 2013-03-07 15:15:57

+0

我将它们结合起来在同一个动画中? ,我需要将UIImageView移出动画。 – Tony 2013-03-07 15:34:44

+0

我可以使用self.face1.center设置x和y来移动UIImageView,现在的问题是如果我尝试设置中心 - (void)touchesBegan:(NSSet *)触及withEvent:(UIEvent *)事件原因,中心不会改变。 – Tony 2013-03-07 15:39:41

回答

0

我找到了办法,我必须设置中心向外一侧的动画:

CGPoint facePosition = CGPointMake(self.face1.center.x+1, 
           self.face1.center.y); 

self.face1.center = facePosition;