iphone - UIButton 在 iOS7 中点击时不显示突出显示

标签 iphone ios objective-c uitableview ios7

我看过大量有关类似内容的帖子,但没有一个完全匹配或解决这个问题。从 iOS 7 开始,每当我将 UIButton 添加到 UITableViewCell 甚至页脚 View 时,它都会“正常”工作,这意味着它会收到目标操作,但不会显示当您点击 UIButton 时通常会出现的小突出显示。它使 UI 看起来很时髦,没有显示按钮对触摸的 react 。

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

编辑: 我忘了提到,如果我长时间按住按钮,它会突出显示,但不会像刚刚添加到标准 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 上的手势识别器,以防它们妨碍。

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

//从单元格中删除手势

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

//这显示了一点轻微的触感,但这不是理想的外观

button.showsTouchWhenHighlighted = YES;

最佳答案

在该表格 View 中,您只需添加此属性即可。

tableview.delaysContentTouches = NO;

并在启动单元格后添加 cellForRowAtIndexPath,只需添加以下代码。 iOS 6 和 iOS 7 中的 Cell 结构明显不同。
iOS 7 我们有一个控件 UITableViewCellScrollView 位于 UITableViewCell 和内容 View 之间。

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

关于iphone - UIButton 在 iOS7 中点击时不显示突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36482141/

相关文章:

iphone - 在 UITableViewController 中的通知中心添加观察者的位置

ios - 在 UINavigationController 中推送 View Controller 时没有动画

ios - 如何刷新UIView

ios - ARC 不允许使用 stringWithUTF8String

ios - 如何获取 .mobileprovision 文件和 .app 文件

iphone - dateFromString 始终使用 dateformatter 返回 null

ios - Objective-C : For loop with images image0001. png

ios - 当我在没有数据漫游的国外时,为什么 iOS 会显示 "home"位置?

iphone - 将 UIImage 传递给第二个 View Controller 会延迟转换

IOS Swift 解包 NSData 崩溃