0

如何获取 UIScrollView 的触摸事件。我有一个 UIViewController,我在 viewController 中放置了一个 scrollView。我需要将 imageViews 添加到 scrollView,如果单击特定图像,它应该重定向到其相应的 viewController。我知道如何将触摸事件添加到 UIViewController。但这不适用于滚动视图。

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch= [touches anyObject];
    if ([touch view] == img1)
    {

        ViewController2 *viewController2=[[ViewController2 alloc]initWithNibName:@"ViewController2" bundle:nil];
        [self presentViewController: viewController2 animated:YES completion:nil];



    }
}

如何获得滚动视图的触摸事件?

4

3 回答 3

0

设置如下:

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];
[scrollView addGestureRecognizer:singleTap];    

and you get the touch in:

- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture
  { 
    CGPoint touchPoint=[gesture locationInView:scrollView];
  }
于 2013-02-05T10:03:14.317 回答
0

您可以使用 ScrollViewDelegate 并且可以使用函数“ScrollViewDidScroll”来获取滚动视图滚动事件。

设置点击手势识别器:

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];
[scrollView addGestureRecognizer:singleTap];   



- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture
  { 
    CGPoint touchPoint=[gesture locationInView:scrollView];
  }
于 2013-02-05T10:03:15.253 回答
0

做到这一点的唯一方法是创建一个自定义UIScrollView您的自定义UIScrollView将是UIScrollView.

此外,您可以查看更多选项

于 2013-02-05T10:02:19.383 回答