UIViewController没有收到touchesBegan消息

时间:2012-05-29 06:01:36

标签: ios uiviewcontroller uiscrollview touch

我的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
        }
    } 
}

2 个答案:

答案 0 :(得分:3)

两种选择:

  1. 子类UIScrollView并实现你的touchesBegan [...]代码 有
  2. 将UIView添加到UIScrollView并使用UIView     touchesBegan [...]委托方法

答案 1 :(得分:0)

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

尝试imgTouchMe.UserInteractionEnabled = true;

或关注

enter image description here