2012-08-29 62 views
3

hy如果移動,UIImageView將縮放而不是旋轉,iOS

我想製作一個小動畫。如果圖像是靜態的,旋轉工作正常。 但當我移動我的圖像視圖時,它會拉伸圖像。如果圖像沒有旋轉,則可以將圖像移動至 。

-(void)play 
{ 

     CGRect ship=image.frame; 
     ship.origin.x=ship.origin.x+move; 
     ship.origin.y=ship.origin.y+move2; 
     image.frame=ship; 
} 

-(void)rotate 
{ 
     int degre=180; 
     float radian=degre*(3.14/180); 
     image.transform =CGAffineTransformMakeRotation(radian); 
} 
+0

這是您的實際代碼? 'CGRect ship = image'看起來很可疑。 - 使用'M_PI'而不是'3.14'! –

回答

3

使用transform屬性時,您不允許通過更改框架來更改位置,您必須使用center屬性。

所以這應該有所幫助:

-(void)play 
{ 
    image.center=CGPointMake(image.center.x + move, image.center.y + move2); 
} 
+0

船沒有一個可變的中心,如果我嘗試在圖像中,它不能直接操縱...寫入快速 – WildWorld

+0

作品,但它將圖像居中在屏幕中間,並保持在那裏 – WildWorld

+0

現在就試試吧,請。它的工作原理是 –