嵌套 ScrollView 无法正确显示
我在尝试实现一对嵌套滚动视图时遇到了一个小问题。 我已经设法实现它们,但是我的图像似乎无法正确显示。它们单独来看都很好,但是随着滚动视图的嵌套,框架似乎改变了大小和位置。
这是我的一些代码,可能可以证明我做错了什么。
- (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许看看您正在实现的委托方法。您将两个滚动视图的委托设置为“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).