UIButton触摸内部事件在ios5中不起作用,而在ios6中没问题 [英] UIButton touch up inside event not working in ios5 while it's ok in ios6

查看:125
本文介绍了UIButton触摸内部事件在ios5中不起作用,而在ios6中没问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含大量UIButton的项目,使用xcode 4.5和storyboard以及ARC。在ios6中测试后,一切都很顺利。但在ios5中,UIButton触及内部事件不起作用,动作未调用。我尝试使用触摸它,它的工作原理。但是,我有很多UIButton,我不能一一改变。更重要的是,触地事件确实提供了良好的体验。

I had a project which contains lots of UIButton, using xcode 4.5 and storyboard and ARC. after testing in ios6, everything goes fine. But in ios5, UIButton touch up inside event not working, the action not called. I tried to use touch down and it works. However, I have a lot of UIButton, I cannot change that one by one. what's more, the touch down event does give a good experience.

我在许多视图控制器中使用了以下代码:viewDidLoad中的

I used code below in many of my view controllers: in viewDidLoad:

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

[self.view addGestureRecognizer:tap];

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

这可能是原因。我稍后会看看。但它适用于ios6。
你知道什么是错的吗?非常感谢!

this might be the reason. I will check it out later. But it works in ios6. Do you know what's wrong ? Thanks very much!

推荐答案

我遇到了同样的问题。
这是因为当您注册的gestureRecognizer捕获事件时,iOS5中的触摸事件被阻止。

I had the same problem to you. That's because the touch event in iOS5 is prevented when the gestureRecognizer you registered captures the event.

有两种解决方案。

一:

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

1) Add a new view inside your view. It should have the same level to the buttons. The priority of the buttons should be higher than the new view.

2)将addGestureRecognizer的调用更改为新视图。

2) change the call of 'addGestureRecognizer' to the new view.

[self.newView addGestureRecognizer:tap];

二:

1)实施代码如下。当点在按钮中时,你应该返回NO。

1) Implement the code below. You should return NO when the point is in the buttons.

- (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;
}

ps。
你应该导入QuartzCore.h来访问图层的属性。

ps. you should import QuartzCore.h to access layer's attributes.

#import <QuartzCore/QuartzCore.h>

这篇关于UIButton触摸内部事件在ios5中不起作用,而在ios6中没问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆