Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何使用滚动视图检测触摸?_Iphone_Xcode_Uiscrollview_Uigesturerecognizer - Fatal编程技术网

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

Iphone 如何使用滚动视图检测触摸?,iphone,xcode,uiscrollview,uigesturerecognizer,Iphone,Xcode,Uiscrollview,Uigesturerecognizer,我希望在用户触摸屏幕时运行一些方法,因此在我的ViewController中实现了touchesbeated:withEvent:method,但当我将滚动视图拖放到iphone上时,touchesbeated:withEvent:method不再被调用 为了尝试修复,我在ViewController中实现了becomeFirstResponder方法,并告诉它返回YES然后在viewDidAppear方法中,我调用了[self becomeFirstResponder] 然而,在这一切之后,它

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

为了尝试修复,我在ViewController中实现了becomeFirstResponder方法,并告诉它
返回YES
然后在viewDidAppear方法中,我调用了
[self becomeFirstResponder]

然而,在这一切之后,它没有起作用

我还尝试创建自定义滚动视图并在其中创建ViewController对象属性,然后在自定义滚动视图的touchesBegind:withEvent:方法中,我实现了它,并说
[self.mainViewController touchesBegind:withEvent]
因此,希望每次我触摸屏幕时,自定义滚动视图上的touchesBegind方法都会被调用,然后由于这个原因,我的vc中的touchesBegind方法会被调用,但这也不会有帮助

我还将我的滚动视图导出到我的vc中,并在其中添加了一个点击手势识别器,并用一个方法和其他东西启动了它。我用它启动的方法被调用了,但只有在我在屏幕内部触动之后,我才希望在触摸屏幕时立即调用该方法

非常感谢您的回答

  • 创建UIScrollView的子类
  • 覆盖结束,如果用户单击而不是拖动,我会手动将消息转发给第一响应者

     @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
    
  • 创建UIScrollView的子类
  • 覆盖结束,如果用户单击而不是拖动,我会手动将消息转发给第一响应者

     @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视图中使用我创建的委托方法实现了touchesBegind:withEvent:方法


    因此,基本上我只需要使用委托。

    为了做到这一点,我只创建了自己的自定义滚动视图类,并在uiscroll视图中用我创建的委托方法实现了touchesbeent:withEvent:method


    因此,基本上我只能使用授权。

    如果对解决问题有用,你可以接受答案如果对解决问题有用,你可以接受答案