我看过大量有关类似事物的帖子,但没有一个完全匹配或解决这个问题。从 iOS 7 开始,每当我添加UIButton
to a UITableViewCell
或者甚至对于页脚视图来说,它工作得“很好”,这意味着它接收到目标操作,但它不会显示当您点击某个按钮时通常会发生的小突出显示UIButton
。它使用户界面看起来很时髦,没有显示按钮对触摸的反应。
我很确定这算作 iOS7 中的一个错误,但是有没有人找到解决方案或可以帮助我找到一个:)
编辑:
我忘了提到,如果我长时间按住按钮,它会突出显示,但不会像刚刚添加到标准视图那样快速点击。
Code:
创建按钮:
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;