UIView旋转和运动

时间:2011-05-09 09:10:08

标签: uiview rotation

我尝试旋转并移动UIImage。 这是我的代码:

im = [[UIImageView alloc ] initWithFrame:CGRectMake(160, 240, 100, 100)];
im.image = [UIImage imageNamed:@"image.png"];
[view addSubview:im];
NSTimer * timer = [NSTimer scheduledTimerWithTimeInterval:1.0/30.0 target:self selector:@selector(actionIm) userInfo:nil repeats:YES];

-(void) actionIm
{
  [im setFrame:CGRectMake(im.frame.origin.x+1 , im.frame.origin.y+1 ,100, 100)];
  im.transform=CGAffineTransformMakeRotation (mRotation);
  mRotation+=0.1;
}

结果是一种非常奇怪的行为:如果我只使用旋转,它就有效。如果我只使用移动,它可以工作。但是这两种用法都给出了一个奇怪的结果(IUImage“跳跃”咆哮)。

我在旋转,框架,边界,中心等方面做了很多事情,但没有什么可以解决我的问题。 谢谢。

1 个答案:

答案 0 :(得分:0)

尝试移动中心而不是更改框架。我相信当旋转不是Identity时设置框架会有所不同。