【发布时间】:2013-10-15 22:11:27
【问题描述】:
我查看了大量关于类似事物的帖子,但没有一个完全符合或解决此问题。从 iOS 7 开始,每当我将 UIButton 添加到 UITableViewCell 甚至添加到页脚视图时,它都会“正常”工作,这意味着它会接收目标操作,但它不会显示通常在您点击 a 时发生的小亮点UIButton。它使 UI 看起来很时髦,没有显示按钮对触摸的反应。
我很确定这算是 iOS7 中的一个错误,但有没有人找到解决方案或可以帮助我找到解决方案 :)
编辑: 我忘了提到,如果我长按按钮,它会突出显示,但不会像刚刚添加到标准视图那样快速点击。
代码:
创建按钮:
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;
【问题讨论】:
-
使用 setTitleColor 高亮状态。 (不确定但也尝试 UIButtonTypeCustom )
-
这并不能解决问题。如果我长按按钮,它将变为突出显示的颜色,但不仅仅是单击
-
在普通 ViewController 中,而不是在滚动视图或表格下的子类 UIButton 存在此问题。有什么想法吗?
标签: iphone ios objective-c uitableview ios7