gpt4 book ai didi

ios - 如何与作为 ScrollView subview 的水平 ScrollView 交互?

转载 作者:行者123 更新时间:2023-11-28 22:37:43 27 4
gpt4 key购买 nike

我有一个水平 ScrollView ,它是垂直 ScrollView 的 subview 。看起来垂直 ScrollView 正在拦截所有用户交互。我希望能够水平滚动水平 ScrollView 。我该怎么做?

这是我的一小段代码:

  UIScrollView *scrollView2 = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0,     self.view.width, 100)];

scrollView2.contentSize = CGSizeMake(self.view.bounds.size.width + 400, 100);

_scrollView.contentSize = CGSizeMake(self.view.width, 400);

_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.height - 108)];

[self.view addSubview:_scrollView];

[_scrollView addSubview:scrollView2];

最佳答案

您可以子类化父 ScrollView 并覆盖 touchesShouldCancelInContentView: 以在 View 是子 ScrollView 时返回 NO。即;

MyScrollView.h

@interface MyScrollView: UIScrollView
@end

在 MyScrollView.m 中

@implementation MyScrollView


-(BOOL)touchesShouldCancelInContentView:(UIView *)touchedView{
if(touchedView == _scrollView2){ //Get the reference of that child scroll view here
return NO;
}else{
[super touchesShouldCancelInContentView:touchedView];
}
}

那么你发布的代码应该是这样的:

UIScrollView *scrollView2 = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0,     self.view.width, 100)];

scrollView2.contentSize = CGSizeMake(self.view.bounds.size.width + 400, 100);



_myScrollView = [[MyScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.height - 108)];
_myScrollView.contentSize = CGSizeMake(self.view.width, 400);


[_myScrollView addSubview:scrollView2];
[self.view addSubview:_myScrollView];

关于ios - 如何与作为 ScrollView subview 的水平 ScrollView 交互?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15445161/

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