UIButton在iOS7中没有显示突出显示 [英] UIButton not showing highlight on tap in iOS7

查看:185
本文介绍了UIButton在iOS7中没有显示突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过很多关于类似事情的帖子,但没有一个匹配或解决这个问题。从iOS 7开始,无论何时我将 UIButton 添加到 UITableViewCell ,甚至到footerview它都能正常工作,这意味着它接收目标动作,但它没有显示通常在您点击 UIButton 时发生的小亮点。它使得UI看起来很时髦而没有显示按钮对触摸的反应。

I've looked at a ton of posts on similar things, but none of them quite match or fix this issue. Since iOS 7, whenever I add a UIButton to a UITableViewCell or even to the footerview it works "fine", meaning it receives the target action, but it doesn't show the little highlight that normally happens as you tap a UIButton. It makes the UI look funky not showing the button react to touch.

我很确定这是iOS7中的一个错误,但是有人找到了解决方案或者可以帮我找到一个:)

I'm pretty sure this counts as a bug in iOS7, but has anyone found a solution or could help me find one :)

编辑:
我忘了提到它会突出显示我是否长按按钮,但不是快速点击它如果只是添加到标准视图中。

I forgot to mention that it will highlight if I long hold on the button, but not a quick tap like it does if just added to a standard view.

代码:

创建按钮:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    button.titleLabel.textColor = [UIColor blueColor];
    [button setTitle:@"Testing" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonPressed:) forControlEvents: UIControlEventTouchDown];
    button.frame = CGRectMake(0, 0, self.view.frame.size.width/2, 40);

我测试的东西:

//删除 UITableView 上的手势识别器,以防他们挡路。

//Removing gesture recognizers on UITableView in case they were getting in the way.

for (UIGestureRecognizer *recognizer in self.tableView.gestureRecognizers) {
   recognizer.enabled = NO;
}

//从单元格中移除手势

//Removing gestures from the Cell

for (UIGestureRecognizer *recognizer in self.contentView.gestureRecognizers) {
       recognizer.enabled = NO;
    }

//这显示了轻微触摸,但这不是理想的看看

//This shows the little light touch, but this isn't the desired look

button.showsTouchWhenHighlighted = YES;


推荐答案

在该表视图中,您只需添加此属性。

In that tableview you just add this property.

tableview.delaysContentTouches = NO;

在启动单元格后添加cellForRowAtIndexPath,只需添加下面的代码即可。在iOS 6和iOS 7中,单元格的结构明显不同。

iOS 7我们有一个控件UITableViewCellScrollView在UITableViewCell和内容View之间。

And add in cellForRowAtIndexPath after you initiate the cell you just add below code. The structure of the cell is apparently different in iOS 6 and iOS 7.
iOS 7 we have one control UITableViewCellScrollView In between UITableViewCell and content View.

for (id obj in cell.subviews)
{
    if ([NSStringFromClass([obj class]) isEqualToString:@"UITableViewCellScrollView"])
    {
        UIScrollView *scroll = (UIScrollView *) obj;
        scroll.delaysContentTouches = NO;
        break;
    }
}

这篇关于UIButton在iOS7中没有显示突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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