0
每次在SO(以及其他地方)詢問此問題時,答案都是「確保contentSize大於視圖大小,並將其設置爲viewDidLoad!」是的,我正在這樣做,那麼還有什麼可能是這個問題?UIScrollView不滾動
在我的控制器的loadView:我有這些線路設置我的觀點:
descriptionView = [[DetailDescriptionView alloc] initWithFrame:CGRectMake(160, 60, 160, 180)];
descriptionScrollView = [[DetailDescriptionScrollView alloc] initWithFrame:CGRectInset(CGRectMake(0, 0, 160, 180), 5, 5)];
[descriptionView addSubview:descriptionScrollView];
[self.view addSubview:descriptionView];
然後,在viewDidLoad中,我有這樣的代碼:
[descriptionScrollView setDescriptionText:@"<lots of text that will require scrolling>"];
NSUInteger contentHeight = <** calculations on the text to determine height **>
[descriptionScrollView setContentSize:CGSizeMake(descriptionScrollView.frame.size.width, contentHeight)];
NSLog(@"ContentSize: %@", NSStringFromCGSize(descriptionScrollView.contentSize));
NSLog(@"DescriptionScrollView Size: %@", NSStringFromCGRect(descriptionScrollView.frame));
那些NSLogs確認所有應罰款:
ContentSize: {150, 330}
DescriptionScrollView Size: {{5, 5}, {150, 170}}
當談到做文本的實際繪圖時,我在使用Core Graphics scrollview的drawRect:方法。這裏是相關的片段:
CGRect descriptionTextBox = CGRectMake(self.frame.origin.x, 20, self.frame.size.width - 10, 330);
[self.descriptionText drawInRect:descriptionTextBox withFont:[UIFont fontWithName:kMediumFontName size:kFontSizeMicro]];
我認爲這涵蓋了我想要做的。滾動不會發生。任何人都可以推薦一個策略來弄清楚要做什麼嘗試做這項工作?