【问题标题】:ipad touch animationipad 触摸动画
【发布时间】:2011-07-22 21:56:56
【问题描述】:

我无法使用触摸为轮子设置动画。我花了一些时间为持续时间、旋转时间和动画持续时间输入不同的数字值,以使用 thouchsMove 获得平滑移动,但每次触摸发生时,轮子都会旋转,似乎正在发生的事情是它跳回原来的位置。如果有人能对此有所了解,我将不胜感激。

CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.fillMode = kCAFillModeForwards;
rotationAnimation.removedOnCompletion = NO;
rotationAnimation.delegate = self; 

rotationAnimation.toValue = [NSNumber numberWithFloat: 2  * 1 * 45 ];
rotationAnimation.duration = 2;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = 1; 


rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];


[animatedImage.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];

【问题讨论】:

  • 我无法重现重置。您能否告诉我们是否有与animatedImage 相关的手势识别器或触摸处理?
  • 嗨,我不确定我是否理解,我正在从 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 调用上述方法
  • 所以你在触摸时开始这个动画,然后在动画结束后,它会回到原来的位置吗?
  • 不完全是,动画在您保持联系时被调用。例如,想象一个音乐转盘,您正在用手指上下移动 LP。我想通过在不抬起手指的情况下以圆周运动移动我的 uiimageview 来创建相同的效果

标签: objective-c ipad cabasicanimation


【解决方案1】:

对于那些感兴趣的代码,下面是获得预期效果所需的代码

CGAffineTransform transforms = CGAffineTransformConcat(animatedImage.transform,CGAffineTransformMakeRotation(M_PI/2));
animatedImage.transform = transforms;

【讨论】:

    【解决方案2】:

    如果您遇到同样的问题,请按照此示例进行操作,它是正确的。 http://ericmcconkie.com/2010/03/trig-and-objective-c/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-13
      • 2011-08-24
      • 2014-12-18
      相关资源
      最近更新 更多