iphone - touchesBegan - iPhone 应用程序 UIView

标签 iphone ios uiview uiviewcontroller touchesbegan

我有一个 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;
    }
}

最佳答案

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

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

关于iphone - touchesBegan - iPhone 应用程序 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6644093/

相关文章:

ios - 观察 UITableViewCell 中 NSArray 的变化

ios - 如何在 Objective-C 中将 BOOL 变量作为参数传递?

ios - UITextView 由于行数和字符数限制文本

swift - 如何从 uitableviewcell 中的 uiview 获取单元格索引 (swift/xcode)

html - iPhone 上的无响应站点中断

ios - 如何在 touchesBegan 上调整自定义 UIView 中的 UILabel 位置?

iphone - 可变高度 UIViews 和标签

iphone - iOS : Movement Precision in 3D Space

iphone - 根据日期更改标签栏图标

ios - 如何将特定的 ViewController 分配给 UIView(在 UICollectionView 中)?