UIScrollView contentSize不起作用,它不是自动布局

时间:2014-04-22 18:46:27

标签: ios uiscrollview

UIScrollView内有contentView contentView内容viewDidAppear。一切都是以编程方式创建的,而不是在IB中(我在IB中避免不同屏幕尺寸约束混乱的方式)。相应的NIB上的Autolayout是关闭的,所以这不是问题。以下所有代码均位于CGRect screenBound = [[UIScreen mainScreen] bounds]; CGSize screenSize = screenBound.size; CGFloat screenHeight = screenSize.height; self.scrollView = [[UIScrollView alloc] initWithFrame: CGRectMake(0, 65, 320, screenHeight)]; scrollView.backgroundColor = [UIColor clearColor]; UIView *contentView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 320, 1200)]; [scrollView addSubview: contentView]; [scrollView setContentSize:contentView.frame.size]; scrollView.contentSize = CGSizeMake(320, 1200); [self.view addSubview:scrollView];

{{1}}

它在iPhone 5上滚动了一点,但只比屏幕尺寸大20个像素。在iPhone 4上,它一直向下滚动到1200像素,没问题。

2 个答案:

答案 0 :(得分:0)

请尝试:

self.scrollView = [[UIScrollView alloc] initWithFrame:
    CGRectMake(0, 65, 320, screenHeight - 65)];

答案 1 :(得分:0)

自己想出来。我在viewDidAppear内加载了所有元素,而不仅仅是scrollView

contentView声明和contentView内的所有元素移动到它自己的函数中,然后在viewDidLoad中声明,它解决了问题并且所有内容都加载正常。< / p>