gpt4 book ai didi

iphone - 嵌套的 UIScrollView - 滚动方向

转载 作者:行者123 更新时间:2023-11-29 11:01:38 27 4
gpt4 key购买 nike

大家好!

我有一个关于嵌套 ScrollView 的问题。

有一个包含嵌套 ScrollView 的 ScrollView 。我将调用 outer-scrollviewinner-scrollview。outer-scrollview 是水平滚动view,inner-scrollviews 是垂直滚动view。

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

_outerScrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
_outerScrollView.pagingEnabled = YES;
_outerScrollView.contentSize = CGSizeMake(_outerScrollView.frame.size.width * 3, _outerScrollView.frame.size.height);
[self.view addSubview:_outerScrollView];

for(int i=0; i<3; i++) {

UIScrollView *innerScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(i * _outerScrollView.frame.size.width,
0,
_outerScrollView.frame.size.width,
_outerScrollView.frame.size.height)];
[_outerScrollView addSubview:innerScrollView];


UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, innerScrollView.frame.size.width, innerScrollView.frame.size.height * 2.0)];
contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"imagefile"]];
[innerScrollView addSubview:contentView];

innerScrollView.contentSize = contentView.frame.size;

}
}

基本上,如果只有1个 ScrollView 会同时滚动。

如果我滚动到,那么outer-scrollview将被滚动。

如果我滚动到顶部底部,那么inner-scrollview将被滚动,

并且,如果我沿对角线滚动,两者之一将被滚动。这取决于滚动的方向。

enter image description here

如果角度为0~45度,inner-scrollview会滚动。如果角度为45~90度,outer-scrollview会滚动。

是否可以更改ANGLE

例如,虽然角度是30度,但我想水平滚动。

谢谢!

任何帮助将不胜感激:)

最佳答案

如果您想要一种简单的方法来实现这种嵌套的 ScrollView 操作,您可以尝试简单地禁用内部 View 的水平滚动并禁用外部 View 的垂直滚动。但是,如果这不能为您提供所需的结果,您将需要进行大量自定义编码。

首先,您需要启动您自己的 UIScrollView 子类。从覆盖这些函数开始:

touchesBegan:
touchesMoved:
touchesEnded:
touchesCancelled:

还有

touchesShouldBegin:

从那里开始,您将必须自己进行计算以确定拖动的角度并相应地向 ScrollView 发送消息,可能是对上述一个或多个函数调用 super。您也可以考虑从头开始编写自己的 ScrollView ,您可以简单地将 UIView 作为子类的 subview 。

关于iphone - 嵌套的 UIScrollView - 滚动方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15652475/

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