触摸事件(touchesMoved)不能在UIScrollView中的UIViews上工作

时间:2013-03-21 06:59:38

标签: iphone ios uiviewcontroller uiscrollview uitouch

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

UserInteraction是所有视图的默认ON,但它仍然无效!

这一定是可能的,如果有人能指出我正确的方向,我真的很感激!

非常感谢,

2 个答案:

答案 0 :(得分:4)

您可以使用以下方法

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

    }
}

答案 1 :(得分:2)

将以下代码添加到实现文件中,然后触及移动

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

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