ios - 接收 touchesBegan:在 UIViewController - Objective C
问题描述
我在 UITableView 上添加了一个 UITableView 作为子视图。我在 UITableView (子视图)上的“传递”触摸到 UIViewController 的视图(我的 touchesBegan: 方法按预期工作)的视图令人不安。
我努力了:
- 子类化我的 UITableView 并从那里传递 touchesBegan: 到 superview
- pointInside:在superview中
- hitTest:在子类tableView中
另外:在我的 tableView 上禁用 userInteraction 有效,但当然,我仍然想维护 cellDidSelectRow.. 功能。
我在 ViewController 中的代码实现:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touchesBegan popup");
if (!self.draggable) {
//[super touchesBegan:touches withEvent:event];
return;
}
UITouch *touch = [touches anyObject];
if (!_moving) {
//(touch.view == self || touch.view.superview == self) &&
_moving = YES;
_movingStartY = [touch locationInView:self.view].y;
NSLog(@"moving popup");
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if (!self.draggable) {
//[super touchesMoved:touches withEvent:event];
return;
}
if (_moving) {
NSLog(@"touchesMoved popup");
UITouch *touch = [touches anyObject];
float offset = [touch locationInView:self.view].y - _movingStartY;
if ([self.touchEventDelegate respondsToSelector:@selector(popupNavigationBar:touchDidMoveWithOffset:)]) {
[self.touchEventDelegate popupNavigationBar:self touchDidMoveWithOffset:offset];
}
}
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
if (!self.draggable) {
//[super touchesCancelled:touches withEvent:event];
return;
}
if (_moving) {
UITouch *touch = [touches anyObject];
float offset = [touch locationInView:self.view].y - _movingStartY;
[self movingDidEndWithOffset:offset];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (!self.draggable) {
//[self touchesEnded:touches withEvent:event];
return;
}
if (_moving) {
UITouch *touch = [touches anyObject];
float offset = [touch locationInView:self.view].y - _movingStartY;
[self movingDidEndWithOffset:offset];
}
}
- (void)movingDidEndWithOffset:(float)offset
{
_moving = NO;
if ([self.touchEventDelegate respondsToSelector:@selector(popupNavigationBar:touchDidEndWithOffset:)]) {
[self.touchEventDelegate popupNavigationBar:self touchDidEndWithOffset:offset];
}
}
我怎样才能做到这一点?
解决方案
推荐阅读
- sonarqube - Checkmarx SonarQube 插件 8.60 中的身份验证失败
- r - r:读取数据集,其中每个观察被分成 2 行?
- css - 无法在每行三对齐图像
- php - 我只能显示全名的第一个单词我想显示完整的字符串
- c# - 带有弹出窗口的 WPF 文本框
- c# - DataGrid 的分页不起作用
- sorting - 在管理员主题中按 desc 排序
- php - 无法从 Intranet 读取图像,php 导出到 word
- java - sonarqube 6.7.2 构建失败 Java 并且无法在报告中存储文件源
- android - 在 DownloadManager DOWNLOAD_COMPLETE 广播接收器上接收广播 Intent 时出错