ios - UIViewController 没有接收到 TouchBegan 消息

标签 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
        }
    } 
}

最佳答案

两个选择:

  1. 子类化 UIScrollView 并实现你的 TouchBegan[...] 代码 那里
  2. 将 UIView 添加到 UIScrollView 并使用 UIView 的 touchesBegan[...] 委托(delegate)方法

关于ios - UIViewController 没有接收到 TouchBegan 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10793809/

相关文章:

ios - 在哪里设置 ios 应用程序的语言特定名称

ios - 在iOS中使用UIDatePicker倒数计时器

ios - 如何处理跳回 iOS 中的先前屏幕

iphone - UIScrollView 不响应 scrollRectToVisible :animated: called from ViewDidLoad in iOS 5

ios - 如何在 iPhone 的 UIScrollview 中隐藏/删除滚动条?

ios - 使用 CATransform3D 性能不佳

ios - 按日期参数过滤项目数组而不考虑时间

iphone - 无法关闭presentModalViewController

ios - 如何在按下时隐藏标签栏并在返回时显示标签栏

iphone - 如何在 iPhone 中检测网页 View 页面是否已到达