UIScrollView within ScrollView - ScrollBars not sh

2019-06-04 05:53发布

问题:

BackStory

I am writing an ipad app which has images that scrolls horizontally using a UIScrollView. This works fine. Now for each image i need to have a UIScrollView which has some kind of text explaining the image. This would be a vertical scrollView. The vertical ScrollView appears but then the scrollbars dont appear. Any idea why? Code below :

CGRect scrollViewFrame = CGRectMake(760, 70, 205, 320);
UIScrollView * contentScrollView = [[UIScrollView alloc]initWithFrame:scrollViewFrame];
[contentView addSubview:contentScrollView];
CGSize scrollViewContentSize = CGSizeMake(205, 100);
[contentScrollView setContentSize:scrollViewContentSize];
[contentScrollView setPagingEnabled:YES];
contentScrollView.delegate = self;

UILabel *titleLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 205, 40)];
UILabel *subtitleLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, 205, 50)];
UITextView * mainContent = [[UITextView alloc]initWithFrame:CGRectMake(10, 110, 205, 230)];

[titleLable setText:storyTitle];
[subtitleLable setText:storySubTitle];
[contentView setUserInteractionEnabled:YES];
[mainContent setText:storyDescription];

Also the main scrolView is already added using Interface Builder and is working fine. Does wnyone know why this is happening?

回答1:

The scroll view only shows scroll-bar and allows user to scroll whenever content size larger than scroll view size, as I see in your code, scroll view size is (205, 320) while content size is only (205, 100).