【问题标题】:UIView RotationUIView 旋转
【发布时间】:2011-03-18 08:22:19
【问题描述】:

您好,我想在单指触摸时旋转 UIView,它仍然会旋转,直到手指在 iPhone 的屏幕上移动,当我停止手指移动或将其从屏幕上移除时它会停止旋转。

提前致谢。

【问题讨论】:

    标签: iphone objective-c uiview cgaffinetransform


    【解决方案1】:

    试试类似的代码

    -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.2]; CGAffineTransform rr=CGAffineTransformMakeRotation(5); yourView.transform=CGAffineTransformConcat(yourView.transform, rr); [UIView 提交动画]; } -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [self touchesBegan:touches withEvent:event]; }

    【讨论】:

      【解决方案2】:

      Pradeepa 的代码很好,但是,动画系统正在被弃用(如果还没有的话)。尝试这样的事情:

      CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
      double startRotationValue = [[[yourView.layer presentationLayer] valueForKeyPath:@"transform.rotation.z"] doubleValue];
      rotation.fromValue = [NSNumber numberWithDouble:startRotationValue];
      rotation.toValue = [NSNumber numberWithDouble:startRotationValue+5];
      rotation.duration = 0.2;
      [yourView.layer addAnimation:rotation forKey:@"rotating"];
      

      我使用 Pradeepa 的数字来比较它们,但我相信 Apple 更喜欢你使用这种或基于块的动画而不是旧系统。

      【讨论】:

        【解决方案3】:

        rotating a view on touch 可以帮到你

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-03-23
          • 2011-04-14
          相关资源
          最近更新 更多