2011-05-09 112 views
2

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

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“跳跃”)。

我冲了很多关于旋转,框架,边界,中心......但没有什么能解决我的问题。 谢谢。

回答

0

尝试移动中心而不是更改框架。我相信设置框架,当旋转不是身份确实做了不同的事情。