2

我有这个功能可以将 UIButtons 旋转 45 度。但是一旦旋转,调用相同的方法不会再旋转,并且按钮在第一次旋转后卡在其旋转位置。有任何想法吗?

- (void)rotateImage:(UIButton *)image duration:(NSTimeInterval)duration 
              curve:(int)curve degrees:(CGFloat)degrees
{
    // Setup the animation
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:duration];
    [UIView setAnimationCurve:curve];
    [UIView setAnimationBeginsFromCurrentState:YES];

    // The transform matrix
    CGAffineTransform transform = 
    CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(degrees));
    image.transform = transform;

    // Commit the changes
    [UIView commitAnimations];
}
4

1 回答 1

4

transform财产是绝对的。如果您想从当前位置进行相对旋转,您需要跟踪按钮的绝对旋转并使用现有方法(可能会更快),或者将新旋转连接到现有旋转中。下面是连接旋转矩阵的代码。

我没有使用我的 Obj-C(我使用 MonoTouch),但它在 C 中可能看起来像这样:

image.transform = image.transform.Rotate(DEGREES_TO_RADIANS(degrees));

或这个:

image.transform = CGAffineTransformationConcat( 
    image.transform, 
    CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(degrees));
)

随意编辑这篇文章以使其成为正确的 Obj-C。

于 2012-09-20T18:18:34.367 回答