gpt4 book ai didi

ios - Cross Directional UIScrollViews - 我可以修改滚动行为吗?

转载 作者:IT王子 更新时间:2023-10-29 07:56:12 25 4
gpt4 key购买 nike

ScrollView 的工作原理如下:一个 ScrollView 在水平方向启用分页。此 ScrollView 的每个“页面”都包含一个垂直滚动的 UITableView。无需修改,这可以正常工作,但并不完美。

不正确的行为:当用户在 TableView 上上下滚动,但随后想快速翻到下一页时,水平轻拂/滑动最初将不起作用 -在表格 View 静止之前它不会工作(即使滑动非常明显是水平的)。

它应该如何工作:如果滑动明显是水平的,我希望即使表格 View 仍在滚动/弹跳,页面也会发生变化,因为这也是用户所期望的.


我怎样才能改变这种行为 - 最简单或最好的方法是什么?


注意 由于各种原因,某些答案中所述的 UIPageViewController 将不起作用。我怎样才能用交叉方向的 UIScrollViews 做到这一点(/one 是一个 TableView ,但你明白了)?几个小时以来,我一直在用头撞墙 - 如果你认为你可以做到这一点,那么我会非常乐意悬赏。

最佳答案

根据我对问题的理解,只有在 tableView 滚动时我们才想更改默认行为。所有其他行为都将相同。

子类 UITableViewUITableViewUIScrollView 的子类。在 UITableView 子类上实现一个 UIScrollViewUIGestureRecognizer 的委托(delegate)方法

- (BOOL)gestureRecognizer:(UIPanGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UISwipeGestureRecognizer *)otherGestureRecognizer
{
//Edit 1
//return self.isDecelerating;
//return self.isDecelerating | self.bounces; //If we want to simultaneous gesture on bounce and scrolling
//Edit 2
return self.isDecelerating || self.contentOffset.y < 0 || self.contentOffset.y > MAX(0, self.contentSize.height - self.bounds.size.height); // @Jordan edited - we don't need to always enable simultaneous gesture for bounce enabled tableViews
}

因为我们只想在 tableView 减速时更改默认手势行为。

现在将所有“UITableView”类更改为您新创建的 tableViewSubClass 并运行项目,滑动应该在 tableView 滚动时起作用。 :]

但是在 tableView 滚动时滑动看起来有点过于敏感。让我们对滑动进行一些限制。

子类 UIScrollView。在 UIScrollView 子类上实现另一个 UIGestureRecognizer 的委托(delegate)方法 gestureRecognizerShouldBegin:

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer 
{
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
CGPoint velocity = [(UIPanGestureRecognizer *)gestureRecognizer velocityInView:self];
if (abs(velocity.y) * 2 < abs(velocity.x)) {
return YES;
}
}
return NO;
}

我们想让“滑动明显是水平的”。如果 x 轴上的手势速度是 y 轴上的两倍,则以上代码仅允许手势开始。 [如果您愿意,可以随意增加硬编码值“2”。滑动需要越水平的值越高。]

现在将“UiScrollView”类(具有多个 TableView)更改为您的 ScrollViewSubClass。运行项目。 :]

enter image description here

我在 gitHub 上做了一个项目 https://github.com/rishi420/SwipeWhileScroll

关于ios - Cross Directional UIScrollViews - 我可以修改滚动行为吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18994434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com