繁体   English   中英

如何使用滚动视图检测触摸?

[英]how can i detect a touch with a scroll view?

我希望在用户触摸屏幕时运行某些方法,因此在ViewController中实现了touchesBegan:withEvent:方法,但是当我将滚动视图拖放到iPhone上时,touchesBegan:withEvent:方法不再被调用。

为了解决这个问题,我在ViewController中实现了beginFirstResponder方法,并告诉它return YES; 然后在viewDidAppear方法中,我调用了[self becomeFirstResponder];

但是,毕竟这没有用。

我还尝试创建一个自定义滚动视图并在其中创建一个ViewController对象属性,然后在我的自定义滚动视图的touchesBegan:withEvent:方法中实现了它说[self.mainViewController touchesBegan:withEvent]所以希望每次我触摸屏幕将调用我的自定义滚动视图上的touchesBegan方法,然后由于该原因,我的vc中的touchesBegan方法将被调用,但这也无济于事。

我还向我的vc制作了一个滚动视图的出口,并向其中添加了一个轻击手势识别器,并使用一种方法和一些东西来启动它,并且该方法以我启动的方法被调用了,但这只是在我触摸了屏幕内部之后,我希望在触摸屏幕后立即调用该方法

非常感谢任何答案!

  1. 创建UIScrollView的子类
  2. 覆盖触摸结束,如果用户单击而不是拖动,则将消息手动转发给第一响应者。

      @interface MyScrollView : UIScrollView { } @end @implementation MyScrollView - (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event { if (!self.dragging) { [self.nextResponder touchesEnded: touches withEvent:event]; } [super touchesEnded: touches withEvent: event]; } @end 

为此,我只创建了自己的自定义滚动视图类,并使用我创建的委托方法在uiscroll视图中实现了touchesBegan:withEvent:方法。

所以基本上我只需要使用委托。

暂无
暂无

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

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