嵌套 ScrollView 无法正确显示

发布于 2024-11-02 08:53:18 字数 1822 浏览 2 评论 0原文

我在尝试实现一对嵌套滚动视图时遇到了一个小问题。 我已经设法实现它们,但是我的图像似乎无法正确显示。它们单独来看都很好,但是随着滚动视图的嵌套,框架似乎改变了大小和位置。

这是我的一些代码,可能可以证明我做错了什么。

- (void)loadView 

{ {

CGRect baseScrollViewFrame = [self frameForBaseScrollView];
baseScrollView = [[UIScrollView alloc] initWithFrame:baseScrollViewFrame];
[baseScrollView     setBackgroundColor:[UIColor blackColor]];
[baseScrollView     setCanCancelContentTouches:NO];
baseScrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
baseScrollView.showsVerticalScrollIndicator = NO;
baseScrollView.showsHorizontalScrollIndicator = YES;
baseScrollView.scrollEnabled = YES;
baseScrollView.pagingEnabled = YES;
//baseScrollView.delaysContentTouches = NO;
baseScrollView.userInteractionEnabled = YES;
baseScrollView.contentSize = CGSizeMake(baseScrollViewFrame.size.width * [self imageCount], baseScrollViewFrame.size.height);

baseScrollView.delegate = self;
self.view = baseScrollView;

[baseScrollView release];

这是用于基本水平滚动视图

CGRect pagingScrollViewFrame = [self frameForPagingScrollView];
pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];
pagingScrollView.pagingEnabled = YES;
pagingScrollView.backgroundColor = [UIColor blackColor];

[pagingScrollView       setCanCancelContentTouches:NO];

pagingScrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
pagingScrollView.showsVerticalScrollIndicator = YES;
pagingScrollView.showsHorizontalScrollIndicator = NO;
pagingScrollView.scrollEnabled = YES;
pagingScrollView.contentSize = CGSizeMake(pagingScrollViewFrame.size.width, pagingScrollViewFrame.size.height * [self imageCount]);

pagingScrollView.delegate = self;

[baseScrollView addSubview:pagingScrollView];

这是用于分页垂直滚动视图。

请有人告诉我我做错了什么。

多谢

I have come across a small problem whilst trying to implement a pair of nested scroll views.
I have managed to implement them however the images i have do not seem to be displaying properly. They were fine individually, but with the scroll views nested the frames seem to change size and position.

and here is some of my code to possibly demonstrate what i am doing wrong.

- (void)loadView 

{ {

CGRect baseScrollViewFrame = [self frameForBaseScrollView];
baseScrollView = [[UIScrollView alloc] initWithFrame:baseScrollViewFrame];
[baseScrollView     setBackgroundColor:[UIColor blackColor]];
[baseScrollView     setCanCancelContentTouches:NO];
baseScrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
baseScrollView.showsVerticalScrollIndicator = NO;
baseScrollView.showsHorizontalScrollIndicator = YES;
baseScrollView.scrollEnabled = YES;
baseScrollView.pagingEnabled = YES;
//baseScrollView.delaysContentTouches = NO;
baseScrollView.userInteractionEnabled = YES;
baseScrollView.contentSize = CGSizeMake(baseScrollViewFrame.size.width * [self imageCount], baseScrollViewFrame.size.height);

baseScrollView.delegate = self;
self.view = baseScrollView;

[baseScrollView release];

This is for the base HORIZONTAL scroll view

CGRect pagingScrollViewFrame = [self frameForPagingScrollView];
pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];
pagingScrollView.pagingEnabled = YES;
pagingScrollView.backgroundColor = [UIColor blackColor];

[pagingScrollView       setCanCancelContentTouches:NO];

pagingScrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
pagingScrollView.showsVerticalScrollIndicator = YES;
pagingScrollView.showsHorizontalScrollIndicator = NO;
pagingScrollView.scrollEnabled = YES;
pagingScrollView.contentSize = CGSizeMake(pagingScrollViewFrame.size.width, pagingScrollViewFrame.size.height * [self imageCount]);

pagingScrollView.delegate = self;

[baseScrollView addSubview:pagingScrollView];

This is for the paging VERTICAL scroll view.

Please someone, tell me what i am doing wrong.

Thanks alot

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

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

发布评论

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

评论(1

转身以后 2024-11-09 08:53:18

也许看看您正在实现的委托方法。您将两个滚动视图的委托设置为“self”。在这些方法中,您是否检查哪个滚动视图调用了它?

根据 imageCount 设置高度和宽度似乎也有点奇怪。例如,如果图像数量为 10,则您将有 100 页(10 页宽 x 10 页高)。

Perhaps looks at the delegate methods that you are implementing. You are setting the delegate of both scrollview's to "self". In these methods, are you checking to see which scrollview called it?

It also seems a bit odd that you are setting BOTH the height and width according to imageCount. If image count were 10 for example, you would have 100 pages (10 pages wide by 10 pages tall).

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