2

我有一个UIView内部 a UIScrollView,并且UIViewControllers这些视图没有接收到触摸事件。如果我将视图从滚动视图中取出,那么它就可以工作。

UserInteraction 是所有视图的默认开启,但它仍然无法正常工作!

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

非常感谢,

4

2 回答 2

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

    }
}
于 2013-03-21T07:09:33.833 回答
2

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

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

   -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesMoved:touches withEvent:event];
}
    @end
于 2013-03-21T07:03:45.677 回答