我有一个 View Controller 子类。我正在尝试连接手势识别器来捕获行下方的点击。
为此,我在底部有一个空行,以便用户始终可以滚动,以便屏幕上有一个空单元格。我可以轻松地捕获这一行上的点击。
但 iOS 7 上的提醒事项即使在这种情况下也支持点击;如果 table 上还有另外三行的空间,则可以点击这三行中的任何一行,而不仅仅是第一行。
例如,您可以点击红色区域:
为了在 iOS 6 上执行此操作,我向表格添加了背景 View ,并在其上挂接了手势识别器:
UIView *backgroundView = [[UIView alloc] init];
[backgroundView addGestureRecognizer:_tapOutsideGesture];
backgroundView.backgroundColor = [UIColor clearColor];
self.tableView.backgroundView = backgroundView;
这在 6.1 上有效,但在 7.0 上无效。我错过了什么?
我使用 Xcode 5.0 和 7.0 SDK 以及 IPHONEOS_DEPLOYMENT_TARGET = 6.1
进行构建。
最佳答案
在表格 View 中添加手势识别器
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doSomething:)];
tapGesture.delegate = self;
[self.tableView addGestureRecognizer:tapGesture];
并检查点击是否位于某个单元格上。
#pragma mark – UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
return ![self.tableView indexPathForRowAtPoint:[touch locationInView:self.tableView]];
}
关于iOS 7 上的 UITableView backgroundView 手势?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19239296/