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 = YE开发者_Go百科S;
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
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).
精彩评论