我制作了具有这种层次结构的 iPhone 应用程序,
: 当我尝试滚动我的 scrollview 它不滚动我在我的项目中使用 Autolayout
我的 ScrollView 的内容大小大于我的 ScrollView 的高度它仍然不滚动。
这是我在 viewDidLoad
中编写的代码片段
UIView *tempo = (UIView *)[scrollVw viewWithTag:6];//View which is inside Scrollview
float sizeOfContent = 0;
for (int i = 0; i < [tempo.subviews count]; i++) {
UIView *view =[tempo.subviews objectAtIndex:i];
sizeOfContent += view.frame.size.height;
}
NSLog(@"sizeOfContent = %f", sizeOfContent);
scrollVw.contentSize = CGSizeMake(scrollVw.frame.size.width, 1500);
NSLog(@"scrollVw width = %f -- scrollVw height =%f",scrollVw.frame.size.width, scrollVw.frame.size.height);
NSLog(@"tempo width = %f -- tempo height =%f",tempo.frame.size.width, tempo.frame.size.height);
记录结果:
sizeOfContent = 1500
scrollVw width = 320.000000 scrollVw height = 416.000000
tempo width = 320.000000 tempo height = 416.000000
我哪里做错了?
最佳答案
如果您使用自动布局,那么您的 View 最终会在 viewDidLoad 之后进行布局。因此,将您的代码移动到 viewWillAppear 或 viewDidLayoutSubviews 中,您应该没问题。
关于ios - UIScrollView 不垂直滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25402848/