我的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
}
}
}
答案 0 :(得分:3)
两种选择:
答案 1 :(得分:0)
使用控制器将UserInteractionEnabled
类的true
属性设置为UIView
。
尝试imgTouchMe.UserInteractionEnabled = true;
或关注