动画UIImageView失去了中心

时间:2013-03-12 23:59:28

标签: ios uiimageview uiviewanimation

我在iOS中遇到了一些我无法弄清楚的问题。

我有一个非常好用的UIImageView动画。 另外,我有一个setCenter,它将UIImageView放在屏幕上的正确位置,也很有效。

问题是,当我尝试设置UIImageView的中心然后启动动画时,动画可以正常工作,但中心不会改变。

动画代码:

-(void)startMirror{

[UIView animateWithDuration:1.0
                      delay:0.0
                    options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse
                 animations:^{
                     self.transform = CGAffineTransformMakeScale(-1, 1);
                 }
                 completion:^(BOOL completed){}];
  }

主要代码:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

 [self.face1 setCenter:CGPointMake(200, 300)];
 [self.face1 startMirror];
}

我用我的问题制作了一个迷你项目,你可以从这里下载we.tl/0gPqkVDCKK 尝试评论并取消注释第46行,您将看到我的问题是什么。

2 个答案:

答案 0 :(得分:1)

我认为你需要在startMirror中进行转换后转换中心点。

答案 1 :(得分:0)

我找到了解决方案,取而代之的是:

[self.face1 setCenter:CGPointMake(200, 300)];

使用:

self.face1.transform = CGAffineTransformMakeTranslation(-11, 80);

在动画中

self.transform = CGAffineTransformScale(self.transform, -1, 1);