简体   繁体   English

触摸事件(touchesMoved)在UIScrollView内的UIView上不起作用

[英]Touch events (touchesMoved) not working on UIViews inside UIScrollView

I have a UIView inside a UIScrollView , and the UIViewControllers for those views are not receiving the touch events. 我在UIScrollView内有一个UIView ,这些视图的UIViewControllers没有收到触摸事件。 If I take the views out of the scroll view then it works. 如果我从滚动视图中取出视图,则它可以工作。

UserInteraction is default ON of all views but it's still not working! UserInteraction默认为所有视图的ON,但仍然无法正常工作!

This must be possible and I'd be really grateful if someone could point me in the right direction! 这一定有可能,如果有人能指出正确的方向,我将不胜感激!

Many Thanks, 非常感谢,

You can use the following method 您可以使用以下方法

 UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
 [panRecognizer setMinimumNumberOfTouches:1];
 [panRecognizer setMaximumNumberOfTouches:1];
 [panRecognizer setDelegate:self];
 [yourView addGestureRecognizer:panRecognizer];

And to handle it 并处理它

 -(void)move:(id)sender {

    if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateChanged){
         // This will return you location in view
         CGPoint currentPoint =  [sender locationInView:self.view];

         // This will return you location in Scrollview
         CGPoint scrollPoint =  [sender locationInView:[[sender view] superview]];

    }
}

add the following code to implementation file then touches moved 将以下代码添加到实现文件中,然后触摸一下

 @interface UIScrollView(Custom)
    @end
    @implementation UIScrollView(Custom)

   -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesMoved:touches withEvent:event];
}
    @end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM