UITableView 取消移动

发布于 2024-09-13 03:22:49 字数 238 浏览 4 评论 0原文

我想要 UITableView 的行为类似于 userInteractionEnabled == NO (表应该停止被用户移动)。但我希望能够在用户移动 UITableView 时激活它,

如果我只是设置

[self.tableView setUserInteractionEnabled:NO];

此行为将在用户停止触摸后激活。

关于我如何实现它有什么想法吗?

I want a behavior of the UITableView like with userInteractionEnabled == NO (The table should just stop being moved by the user). But I want to be able to activate it while the user is moving the UITableView

If I just set

[self.tableView setUserInteractionEnabled:NO];

This behavior will activate after the user ceases to touch.

Any idea on how I could accomplish it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゝ杯具 2024-09-20 03:22:49

您可以子类化 UITableView 并覆盖 attemptsEnded:withEvent:。当用户松开手指时,此方法就会被触发。由于您可能不想在用户点击屏幕时禁用用户交互,因此您可以捕获初始触摸起点和触摸终点。从这两者中,您可以比较 Y 的增量,以确定在禁用用户交互之前您希望用户移动多少。这里有一些代码可以为您提供帮助。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  UITouch * touch = [touches anyObject];
  touchStartPoint = [touch locationInView:self];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  UITouch * touch = [touches anyObject];
  CGPoint touchEndPoint = [touch locationInView:self];
  CGFloat deltaY = touchStartPoint.y - touchEndPoint.y;

  if (fabsf(deltaY) >= kMinimumYMoved) {
      self.userInteractionEnabled = NO;
  }
}

You can subclass UITableView and override the touchesEnded:withEvent:. This method gets hit when the user lifts their finger off. Since you may not want to disable the user interaction when the user just taps the screen, you can capture the initial touch start point and the touch end point. From these two, you can compare the deltas of the Y to figure out how much you want the user to move before disabling the the user interaction. Here's some code that will help you along the way.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  UITouch * touch = [touches anyObject];
  touchStartPoint = [touch locationInView:self];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  UITouch * touch = [touches anyObject];
  CGPoint touchEndPoint = [touch locationInView:self];
  CGFloat deltaY = touchStartPoint.y - touchEndPoint.y;

  if (fabsf(deltaY) >= kMinimumYMoved) {
      self.userInteractionEnabled = NO;
  }
}
走过海棠暮 2024-09-20 03:22:49

我找到了怎么做,我不敢相信我错过了这个属性:

[myTableView setScrollEnabled:NO];

I found out how to do it, I can't believe I missed this property:

[myTableView setScrollEnabled:NO];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文