【问题标题】:Rotating UIView with button in it旋转带有按钮的 UIView
【发布时间】:2012-09-04 11:31:58
【问题描述】:

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

【问题讨论】:

  • 放上你的旋转动画代码了解详情

标签: iphone uiview rotation imageview


【解决方案1】:

使用 CGAFFINETRANSFORM 进行旋转

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

【讨论】:

  • 是的,我试过了,但是在它移动时我无法按下按钮。
猜你喜欢
  • 2020-11-11
  • 2022-01-11
  • 1970-01-01
  • 1970-01-01
  • 2011-08-12
  • 2015-05-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多