Ios UIViewController未接收TouchesBegind消息

Ios UIViewController未接收TouchesBegind消息,ios,uiviewcontroller,uiscrollview,touch,Ios,Uiviewcontroller,Uiscrollview,Touch,我的UIViewController中有一个UIScrollView。我需要检测到任何触摸,然后做点什么。我还需要什么 - (BOOL)canBecomeFirstResponder { return YES; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self becomeFirstResponder]; } -(void)touchesBegan:(NSSet

我的UIViewController中有一个UIScrollView。我需要检测到任何触摸,然后做点什么。我还需要什么

- (BOOL)canBecomeFirstResponder {
    return YES;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self becomeFirstResponder];
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"TOUCHED"); // never happens
    for (UITouch *touch in touches) {
        if ( [touch view] == self.myScrollView)
        {
            //do something
        }
    } 
}
两种选择:

  • 子类UIScrollView并实现touchesBegind[…]代码 那里
  • 将UIView添加到UIScrollView并使用UIView的 touchesbreated[…]委托方法

  • 使用控制器将
    UIView
    类上的
    UserInteractionEnabled
    属性设置为
    true

    尝试
    imgTouchMe.UserInteractionEnabled=true

    或跟随


    滚动视图是否覆盖了整个视图控制器?如果是这样,那么它是响应器链中的第一个。不,它只是视图的一部分。如何让scrollview将触摸事件转发到视图控制器?实际上,触摸在视图控制器上的任何位置都不会被检测到,即使在非scrollview的视图上也是如此。您确实为它启用了触摸,对吗?