用按钮旋转UIView

时间:2012-09-11 13:54:23

标签: iphone uiview rotation imageview

我正在尝试旋转一个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"]; 

1 个答案:

答案 0 :(得分:0)

使用CGAFFINETRANSFORM进行旋转

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2];
    CGAffineTransform transform=CGAffineTransformMakeRotation(3.14159265);
    yourView.transform=transform;
[UIView commitAnimations];