我的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并实现您的touchesBegan [...]代码
  • 将UIView添加到您的UIScrollView并使用该UIView的
    touchesBegan [...]委托方法
  • 关于ios - UIViewController没有收到touchesBegan消息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10793809/

    10-10 20:44