我发生了这个问题,我水平添加了一个滚动视图和一个UITextview
滚动视图,但是在模拟器中视图不能很好地滚动。
我的问题是:如何设置 contentsize 以使其滚动?
这是代码:
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.title = scenery.name;
mainScrollView = [[UIScrollView alloc] init];
self.imagePaths = [scenery imagePaths];
imageScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 240)];
imageScrollView.directionalLockEnabled = YES;
imageScrollView.pagingEnabled = YES;
imageScrollView.showsVerticalScrollIndicator = NO;
imageScrollView.showsHorizontalScrollIndicator = NO;
[self AddImgsToScrollView];
self.currentPage = 0;
[NSTimer scheduledTimerWithTimeInterval:1 target: self selector: @selector(handleTimer:) userInfo:nil repeats: YES];
[mainScrollView addSubview:imageScrollView];
//Introduction Text View
introView = [[UITextView alloc] init];
introView.text = scenery.introduction;
introView.editable = NO;
introView.font = [UIFont systemFontOfSize:16.0f];
[introView setScrollEnabled:NO];
CGSize textViewSize = [introView.text sizeWithFont:introView.font constrainedToSize:CGSizeMake(WIDTH-20, FLT_MAX)];
CGRect newFrame = introView.frame;
newFrame.size = textViewSize;
newFrame.origin = CGPointMake(10,245);
introView.frame = newFrame;
[mainScrollView addSubview:introView];
CGFloat scrollViewHeight = 0.0f;
for (UIView *view in mainScrollView.subviews){
if (scrollViewHeight < view.frame.origin.y + view.frame.size.height) scrollViewHeight = view.frame.origin.y + view.frame.size.height;
}
newFrame = mainScrollView.frame;
newFrame.size = CGSizeMake(WIDTH, scrollViewHeight);
mainScrollView.frame = newFrame;
NSLog(@"%f/%f", scrollViewHeight,textViewSize.height);
[mainScrollView setContentSize:CGSizeMake(WIDTH, scrollViewHeight)];
[self.view addSubview:mainScrollView];
}