iOS 7 上的 UITableView backgroundView 手势?

标签 uitableview ios7 uigesturerecognizer

我有一个 View Controller 子类。我正在尝试连接手势识别器来捕获行下方的点击。

为此,我在底部有一个空行,以便用户始终可以滚动,以便屏幕上有一个空单元格。我可以轻松地捕获这一行上的点击。

但 iOS 7 上的提醒事项即使在这种情况下也支持点击;如果 table 上还有另外三行的空间,则可以点击这三行中的任何一行,而不仅仅是第一行。

例如,您可以点击红色区域:

enter image description here

为了在 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/

相关文章:

swift - 屏幕边缘手势识别器问题

ios - Swift 4 - 尝试在 AVPlayerViewController 中从后端显示 AWS 视频 url 不起作用,出现奇怪的错误

ios - 变量在 URLSESSION 中不可用

ios - 什么是 iOS 7 中的 AppleBasebandManager 框架?

ios - 远程通知不会在后台启动应用程序

objective-c - 顶部检测触摸的透明 UIView

ios - 在没有 Storyboard的情况下以编程方式在 UITextField 上调用 resignFirstResponder

ios - 如果我选择一行或移动一个 uitableview,将调用 "moveRowAtIndexPath"

ios - 如何在 Swift iOS 应用程序中隐藏状态栏?

ios - 我需要在页面控件内的 tableView 上检测滑动手势,我该怎么做?