【问题标题】:Rotate the wheel to a specific point将滚轮旋转到特定点
【发布时间】:2012-11-10 19:25:32
【问题描述】:

在这个轮子中,我们有 6 个零件。轮子的顶部是特定点。具体点给出了碎片的信息。现在它给出了蓝色部分的信息。因此,如果我单击其中一个,例如紫色,我需要该紫色块到达特定点并自动进入有关紫色块的给定信息。

    CGFloat topPositionAngle = radiansToDegrees(atan2(view.transform.a, view.transform.b));
  1. -180 - 粉红色
  2. -120 - 蓝色
  3. -60 - 橙色
  4. 0 - 紫色
  5. 60 - 黄色
  6. 120 - 绿色

现在 topPositionAngle 显示 -120 = 蓝色,当紫色到达特定点时显示 0。

    UITouch *touch = [touches anyObject];
    CGPoint currentTouchPoint = [touch locationInView:view];
    CGFloat currentAngle = radiansToDegrees(atan2(currentTouchPoint.x, currentTouchPoint.y));

    CGFloat angleTransform = ???
    CGAffineTransform current = view.transform;
    [UIView animateWithDuration:0.2f animations:^{
        [view setTransform:CGAffineTransformRotate(current, angleTransform)];
    }];

我们如何才能自动旋转到特定点?就像 Dansk Bank 应用程序(请参阅以下 youtube 链接)类似于 0:21 - 0:25 分钟的视频。

http://www.youtube.com/watch?v=hulBh_KNGjE

【问题讨论】:

  • 您的问题看起来类似于 Raywenderlich 教程。检查可能对您有帮助的链接Click here 很高兴为您提供帮助。如果你想要整个项目从 Github 链接下载。 Click to download project
  • 感谢您的重播,但我已经通过 Raywenderlich 教程,它只解释了车轮的旋转。我需要一个特定的,当我点击一个地方时它可以旋转,并且那个区域应该进入一个特定的地方。就像我点击紫色区域一样,它应该一直旋转到蓝色区域,这是“主要区域”。因此,您单击的任何内容都应移动到该特定位置。有代码吗?
  • 它看起来并不相似——它是一个副本。

标签: ios rotation transform


【解决方案1】:
float fromAngle = atan2(m_locationBegan.y-img.center.y, m_locationBegan.x-img.center.x);
float toAngle = atan2(_location.y-imgDigits.center.y, _location.x-img.center.x);
float newAngle = wrapd(m_currentAngle + (toAngle - fromAngle), 0, 2*3.14);
angle = newAngle;

CGAffineTransform transform = CGAffineTransformMakeRotation(newAngle);
img.transform = transform;

使用类似的东西。希望这可以帮助 在这里你应该知道接触点和你的具体点

【讨论】:

    【解决方案2】:

    你需要知道的触摸点角度:

    CGFloat touchedPointAngle = atan2f(touchPoint.y - centerSuper.y, touchPoint.x - centerSuper.x) + M_PI;
    
    if ((touchedPointAngle < sliceInRadians) && (touchedPointAngle > 0)) {
            angleTransform = sliceInRadians;
    } else if ...
    

    然后你就可以变形了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      相关资源
      最近更新 更多