iphone - UIView 触摸问题/问题

标签 iphone ios uiimageview

我的应用程序有点问题。我质疑我的方法。

这是一张图片 Sample App

基本上我需要色轮在透明盒子里旋转。到目前为止,我所拥有的是有效的。我可以拖动色轮,它会旋转。问题是我可以触摸并拖动屏幕上的“任何地方”,它会旋转。我只希望它在“窗口”中旋转。

我基本上添加了一个 UIView 和一个 UIImageView,向 ImageView 添加了 socket ,并在 touchesBegan 和 touchesMoved 中添加了代码来执行动画。轮子是一个完整的圆形图像, subview 被“裁剪”以不显示图像的下半部分。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *thisTouch = [touches anyObject];
    delta = [thisTouch locationInView:wheelImage];

    float dx = delta.x  - wheelImage.center.x;
    float dy = delta.y  - wheelImage.center.y;
    deltaAngle = atan2(dy,dx); 

    initialTransform = wheelImage.transform;   
  }

  - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
      UITouch *touch = [touches anyObject];
  CGPoint pt = [touch locationInView:wheelImage];

  float dx = pt.x  - wheelImage.center.x;
  float dy = pt.y  - wheelImage.center.y;
  float ang = atan2(dy,dx);

  //do the rotation
  if (deltaAngle == 0.0) {
    deltaAngle = ang;
    initialTransform = wheelImage.transform;
  }else
  {
    float angleDif = deltaAngle - ang;
    CGAffineTransform newTrans = CGAffineTransformRotate(initialTransform, -angleDif);
    wheelImage.transform = newTrans;
    
    currentValue = [self goodDegrees:radiansToDegrees(angleDif)];
    
  }

  }

现在...我的问题如下:

  1. 如何让 touchesMoved/Began 仅在 UIView 或 UIImageView 上工作?
  2. 我应该为这个轮子创建一个自定义 UIView,然后将它添加到我的主视图 Controller 吗? 2.a.如果我确实创建了一个自定义项,我会遇到同样的触摸问题吗?

最佳答案

您可能需要考虑使用 UISwipeGestureRecognizer 并将其仅添加到您希望识别滑动的 View 中。

关于iphone - UIView 触摸问题/问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6458931/

相关文章:

ios - 为内存释放 UIImageViews

ios - uitableViewCell 内容行为异常

ios - 从容器 View 调用父 View Controller 函数

iphone - 为什么我的录音无法播放? (iPhone SDK)

ios - UITabBar 项目不会选择

iphone - 传递给另一个类时 NSDictionary 设置为 nil (IOS)

ios - 从 Google/Facebook 帐户重新验证用户身份

ios - Firebase 云消息传递 iOS : No background push notification

ios - 使用 UIImage 放大 ScrollView

ios - scrollToRowAtIndexPath 没有正确处理最后一行