简体   繁体   English

移动和旋转UIImageView

[英]Move & Rotate an UIImageView

I have an UIImageView with an rotation animation that loops, I need to move the UIImageView by x and y in the screen. 我有一个带有循环旋转动画的UIImageView,我需要在屏幕上按x和y移动UIImageView。

The rotation animation code is: 旋转动画代码为:

-(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];
                         }
                     }
                 }];
}

I try differents approaches to move the image, like setting the center but I cant move it. 我尝试了不同的方法来移动图像,例如设置中心,但是我无法移动它。

I found the way, I have to set the center out side the animation: 我找到了方法,我必须将中心设置在动画之外:

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

self.face1.center = facePosition;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM