简体   繁体   English

UITapGestureRecognizer无法在iOS9上运行

[英]UITapGestureRecognizer not working on iOS9

I have an application which uses UITapGestureRecognizers which seem to not work in iOS9 Beta 2. 我有一个使用UITapGestureRecognizers的应用程序,似乎在iOS9 Beta 2中不起作用。

They are successfully calling 他们成功地打电话了

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
  NSLog(@"shouldReceiveTouch");
  return YES;
}

but it doesn't hit any of the other UITapGesture delegate methods. 但它没有击中任何其他UITapGesture委托方法。

When I run the same application (from Xcode 7) on a device running on iOS 8, it works as expected. 当我在iOS 8上运行的设备上运行相同的应用程序(来自Xcode 7)时,它按预期工作。

Has anyone else hit this? 还有其他人打过这个吗?

Here is how I initialise the UITapGestureRecognizer. 以下是我初始化UITapGestureRecognizer的方法。 TapGestureRecognizerSetup

Edit 编辑
If I create the UITapGestureRecognizer in code instead of in the ViewController xib it works fine, so there's something up with the xib parsing in iOS9 or something. 如果我在代码中而不是在ViewController xib中创建UITapGestureRecognizer它可以正常工作,那么iOS9中的xib解析就可以了。

_tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onMainViewTap:)];
_tapGesture2.numberOfTapsRequired = 1;
_tapGesture2.delegate = self;
[self.view addGestureRecognizer:_tapGesture2];

Edit2 EDIT2
If I deleted the GestureRecognizer in the XIB and added it back in again using XCode 7, it also worked. 如果我删除了XIB中的GestureRecognizer并使用XCode 7再次将其添加回来,它也有效。 When I did this, it added <pressTypeMask key="allowedPressTypes"/> into the xib under the UITapGestureRecognizer. 当我这样做时,它将<pressTypeMask key="allowedPressTypes"/>到UITapGestureRecognizer下的xib中。

It seems that iOS9 looks for a <pressTypeMask key="allowedPressTypes"/> line in the xml of the gesture recognizer and the tap recognizer doesn't work without it. 似乎iOS9在手势识别器的xml中查找<pressTypeMask key="allowedPressTypes"/>行,如果没有它,则点击识别器不起作用。 To fix you can either build your recognizers in code, add that line into the xml or delete and re-add the gesture recognizer in Xcode 7, which will properly add the pressTypeMask into the xml. 要解决此问题,您可以在代码中构建识别器,将该行添加到xml中,或删除并在Xcode 7中重新添加手势识别器,这将正确地将pressTypeMask添加到xml中。

I wonder if apple will fix iOS9 to work without that line in the XML, but for now, this is an easy fix. 我想知道苹果是否会在没有XML的那一行的情况下修复iOS9,但是现在,这是一个简单的修复。

I ran into this problem as well, specifically when trying to get both my buttons and views w/ tap gestures within a table cell to respond to a click whose layout was defined in a xib. 我也遇到了这个问题,特别是当试图获取我的按钮和视图时,在表格单元格中点击手势以响应其布局在xib中定义的点击。 Worked fine on iOS 8 & 10, but not 9. The actual problem was that I added those to a custom uiview and assigned the view's class to my UITableViewCell subclass, rather than use a Table View Cell object within IB. 在iOS 8和10上工作得很好,但不是9.真正的问题是我将它们添加到自定义uiview并将视图的类分配给我的UITableViewCell子类,而不是在IB中使用Table View Cell对象。 Thus I did not add my subviews to the contentView that the IB object gives you, causing me the problem. 因此,我没有将我的子视图添加到IB对象为您提供的contentView ,从而导致我遇到问题。 The fix was to redo the xib to use the Table View Cell as my root, so I could attach my subviews to the Content View. 修复是重做xib以使用表视图单元格作为我的根,所以我可以将我的子视图附加到内容视图。

实现UIGestureRecognizer的所有可选委托将起作用。

I checked it via Xcode-7 beta 2 我通过Xcode-7 beta 2检查了它

I've created vc with gesturerecognizer and create outlets for property and action. 我用gesturerecognizer创建了vc,并为属性和动作创建了出口。 in viewDidload setted delegate, like this: 在viewDidload中设置了委托,如下所示: 在此输入图像描述

All methods, that was called during debug - i've marked //called 在调试期间调用的所有方法 - 我都标记为//被调用

I received events to the next methods: 我收到了下一个方法的事件:

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
    print("worked")
    // called
    return true
}

 func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool
 {
    //called
    print("worked")
    return true
}


 func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOfGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool
 {
    print("worked")
    //called
    return true
}

Try recreate project as i mentioned and check all your outlets and delegate 尝试重新创建我提到的项目并检查所有的商店和代表

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM