2011-04-20 40 views
0

當第一次旋轉UIImageView並將其動畫框架時,我目前遇到了麻煩。只要我開始將它的框架動畫到target_position,我的圖像就會改變它的大小。它得到更廣泛和更高(根據旋轉角度)使用UIView更改框架來旋轉UIImageView動畫更改它的尺寸

我目前使用的旋轉的代碼是:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    if (!isAnimating) { 
     isAnimating = YES; 
     UITouch *t = [[touches allObjects] lastObject]; 

     float angle = atan2([t locationInView:self.view].y - player.frame.origin.y, [t locationInView:self.view].x - player.frame.origin.x) * 180/M_PI; 
     NSLog(@"Angle: %f", angle); 

     CGAffineTransform cgCTM = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(angle)); 

     [player setTarget_position:CGRectMake([t locationInView:self.view].x, [t locationInView:self.view].y, player.image.size.width-angle, player.image.size.height+angle)]; 

     [UIView beginAnimations:@"rotatePlayer" context:nil]; 
     [UIView setAnimationDuration:2]; 
     player.transform = cgCTM; 
     [UIView setAnimationDelegate:self]; 
     [UIView setAnimationDidStopSelector:@selector(playerFinishedRotating)]; 
     [UIView commitAnimations]; 
    } 
} 

旋轉本身運行正常。這是playerFinishedRotating函數的代碼:

- (void)playerFinishedRotating { 
    [UIView beginAnimations:@"rotatePlayer" context:nil]; 
    [UIView setAnimationDuration:3]; 
    [player setFrame:[player target_position]]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(playerFinishedAnimating)]; 
    [UIView commitAnimations]; 
} 

對我來說,它是一種合乎邏輯的,而旋轉的我UIImageVie改變它的大小。但我堅持如何用給定的數據(旋轉角度f.e.)來調整我的target_position幀的寬度和高度值。

我不是一個數學天才,所以對於其他人的答案可能是顯而易見的,但對我來說這不是:(

希望有人能幫助,如果您還有其他問題,請LEVE評論。

回答