【问题标题】:touchesBegan - iPhone app UIViewtouchesBegan - iPhone 应用程序 UIView
【发布时间】:2011-07-10 22:14:21
【问题描述】:

我有一个工作正常的touchesBegan: 方法。但是我最近在我的 UIViewController 中添加了一个 UIView(一个按钮),现在该按钮没有注册点击,但是我的 touchesBegan: 方法是。

我怎样才能告诉我的touchesBegan: 方法避免使用该按钮?

这是我当前的touchesBegan: 方法:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event  {
    NSLog(@"touches began");
    UITouch *touch = [touches anyObject];   
    switch ([touch tapCount]) 
    {
        case 1:
            break;

        case 2:
            if(something)
                [doing something];

            break;

        default:
            break;
    }
}

【问题讨论】:

  • 与往常一样,如果您在 IB 中创建按钮,请仔细检查以确保您已正确连接 IB 中的按钮。

标签: iphone ios uiview uiviewcontroller touchesbegan


【解决方案1】:

确保按钮在前面 ([self.view bringSubviewToFront: myButton])。然后你可以询问发生在哪个视图中的触摸:

if ([touch.view isEqualTo: myButton]) {
    NSLog(@"touch was on button");
}

【讨论】:

    【解决方案2】:

    我遇到了同样的问题。当我将按钮移到前面时(通过 UIViewController.bringSubviewToFront 的代码),当我单击按钮时不再触发 touchesBegan。我在模拟器中运行 Xcode 4.2。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-15
      • 2013-01-29
      • 1970-01-01
      • 1970-01-01
      • 2011-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多