【问题标题】:Pass all the events of a UIGestureRecognizer from one UIView to another UIView (subview) [duplicate]将 UIGestureRecognizer 的所有事件从一个 UIView 传递到另一个 UIView(子视图)[重复]
【发布时间】:2014-01-02 23:49:32
【问题描述】:

我有一个带有手势识别器的 UIView。

在某些情况下(例如在某个区域点击)我想将点击传递给子视图。

子视图的用户交互被禁用(例如,因为我不希望它接收滑动)。

如果我希望它接收事件 - 如何实现。

【问题讨论】:

  • 对不起,Avner,问同样的问题不太礼貌twice in the same day
  • 为了清楚起见,它使用不同的语言。也许第一个解释不清楚。我真的只是想要一个答案
  • 如果您发现您的原始问题不清楚,您应该对其进行编辑以使其更清晰,而不是开始新问题(除非是针对新问题)。
  • 复制您的问题会阻止任何人撰写经过深思熟虑的回复。请耐心等待 - 好的答案很少能很快得到。
  • 应该编辑您之前的问题,以便在必要时澄清或扩展,而不是创建第二个问题。

标签: ios iphone objective-c uiview uigesturerecognizer


【解决方案1】:

这里是处理手势事件的代码。

 UIPanGestureRecognizer * moveGesture = [[UIPanGestureRecognizer alloc]
                                        initWithTarget:self
                                     action:@selector(onMove:)];
 [moveGesture setDelegate:self];

将 UIGestureRecognizerDelegate 添加到您的视图类委托中,然后实现这样的功能:

- (void) onMove:(UIPanGestureRecognizer*)gesture {
 switch (gesture.state) {
    case UIGestureRecognizerStateBegan:
    {
         //handle the events here
         //and don't forget if you want to your view receive touches
         //userInteraction must be enabled.

         //if you want to get touch in your super view you just do this:
         CGPoint pointToSuperview = [gesture locationInView:self.superview];
         //this is the point where touch is received to your superview 
    }
        break;
    case UIGestureRecognizerStateChanged:
    {

    }
        break;
    case UIGestureRecognizerStateEnded:
    case UIGestureRecognizerStateCancelled:
    case UIGestureRecognizerStateFailed:
    {

    }
        break;
    default:
        break;
}
}

【讨论】:

  • 这根本没有回答我的问题!
猜你喜欢
  • 2011-10-01
  • 2017-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-20
  • 1970-01-01
相关资源
最近更新 更多