gpt4 book ai didi

ios5 - UIButton 内部事件在 ios 5 中不起作用,而在 ios 6 中则可以

转载 作者:行者123 更新时间:2023-12-04 09:32:03 25 4
gpt4 key购买 nike

我有一个包含大量 UIButton 的项目,使用 xcode 4.5 和 Storyboard和 ARC。在ios6中测试后,一切正常。但是在 ios5 中,UIButton touch up 里面的事件不起作用, Action 没有被调用。我尝试使用着陆并且它有效。但是,我有很多 UIButton,我无法一一更改。更重要的是,着陆事件确实提供了很好的体验。

我在许多 View Controller 中使用了以下代码:
在 View DidLoad中:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(dismissKeyboard)];

[self.view addGestureRecognizer:tap];

-(void)dismissKeyboard {
[aTextField resignFirstResponder];
}

这可能是原因。稍后我会检查它。但它适用于ios6。
你知道怎么回事吗?非常感谢!

最佳答案

我和你有同样的问题。
那是因为当您注册的gestureRecognizer 捕获事件时,阻止了iOS5 中的触摸事件。

有两种解决方案。

一:

1) 在您的 View 中添加一个新 View 。它应该与按钮具有相同的级别。按钮的优先级应该高于新 View 。

2) 将'addGestureRecognizer' 的调用更改为新 View 。

[self.newView addGestureRecognizer:tap];

二:

1)实现下面的代码。当点在按钮中时,您应该返回 NO。
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
CGPoint point = [gestureRecognizer locationInView:self.view];

NSLog(@"x = %.0f, y = %.0f", point.x, point.y);
if (CGRectContainsPoint(self.testBtn.layer.frame, point))
return NO;

return YES;
}

附:
你应该导入 QuartzCore.h 来访问层的属性。
#import <QuartzCore/QuartzCore.h>

关于ios5 - UIButton 内部事件在 ios 5 中不起作用,而在 ios 6 中则可以,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13854045/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com