嵌套的ScrollViews无法正常显示

时间:2011-04-18 14:59:55

标签: iphone ios uiview uiscrollview addsubview

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

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

- (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];

这是基础HORIZONTAL滚动视图

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];

这是用于分页VERTICAL滚动视图。

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

非常感谢

1 个答案:

答案 0 :(得分:0)

或许查看您正在实现的委托方法。您正在将两个scrollview的委托设置为“self”。在这些方法中,您是否正在检查哪个scrollview称为它?

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