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