1

我正在尝试旋转一个 UIview,它在左上角有一个 UIButton 与操作:

NSLog@"hello";

现在我将 UIView 旋转 180°,按钮现在位于右下角。但是只有当我按下左上角时按钮才会触发它的动作......所以它就像按钮位置已经改变但它的动作保持在与旋转前相同的位置?

我用CAKeyframeAnimation.

CAKeyframeAnimation *rotationAnimation;
rotationAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];

rotationAnimation.values = [NSArray arrayWithObjects:
                            [NSNumber numberWithFloat:0.0 * M_PI], 
                            [NSNumber numberWithFloat:0.75 * M_PI],
                            [NSNumber numberWithFloat:1.5 * M_PI], 
                            [NSNumber numberWithFloat:2.0 * M_PI], nil]; 
rotationAnimation.calculationMode = kCAAnimationPaced;


rotationAnimation.removedOnCompletion = NO;
rotationAnimation.fillMode = kCAFillModeForwards;

rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
rotationAnimation.duration = 10.0;

CALayer *layer = [rotateView layer];
[layer addAnimation:rotationAnimation forKey:@"rotationAnimation"]; 
4

1 回答 1

0

使用 CGAFFINETRANSFORM 进行旋转

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2];
    CGAffineTransform transform=CGAffineTransformMakeRotation(3.14159265);
    yourView.transform=transform;
[UIView commitAnimations];
于 2012-09-11T14:33:06.293 回答