繁体   English   中英

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

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

我在UIScrollView内有一个UIView ,这些视图的UIViewControllers没有收到触摸事件。 如果我从滚动视图中取出视图,则它可以工作。

UserInteraction默认为所有视图的ON,但仍然无法正常工作!

这一定有可能,如果有人能指出正确的方向,我将不胜感激!

非常感谢,

您可以使用以下方法

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

并处理它

 -(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]];

    }
}

将以下代码添加到实现文件中,然后触摸一下

 @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