简体   繁体   English

iOS7的UIScrollView中奇怪的contentSize

[英]Strange contentSize in UIScrollView of ios7

I add a scrollview as a subview by using the storyboard. 我使用情节提要将滚动视图添加为子视图。

here is my code 这是我的代码

[self.bottomScrollView setBackgroundColor:[UIColor greenColor]];
UIView* v = [[UIView alloc] initWithFrame:self.bottomScrollView.bounds];
[v setBackgroundColor:[UIColor redColor]];
[self.bottomScrollView addSubview:v];
[self.bottomScrollView setContentSize:v.frame.size];

in which self.bottomScrollView is the subview which is added by storyboard. 其中self.bottomScrollView是情节提要添加的子视图。 I think because the contentsize is equal to the view v and the frame of v start from (0,0), the scrollview should not be able to be moved either horizontally or vertically. 我认为,因为contentsize等于视图v,并且v的帧从(0,0)开始,所以滚动视图应该不能水平或垂直移动。

However, the result is quite strange, the bottomScrollView still can be scrolled viertically as the following image shows.(this is not the bounce) 但是,结果很奇怪,bottomScrollView仍然可以像下面的图像一样直观地滚动(这不是反弹) 在此处输入图片说明

Acutally, I tried add a scrollview programly and it works correct. 手动地,我尝试以编程方式添加一个scrollview,它可以正常工作。 Why this happens? 为什么会这样? Any bugs of storyboard? 故事板有任何错误吗?

将NO设置为self.automaticallyAdjustsScrollViewInsets属性,则滚动视图将不会显示这种“奇怪的”偏移量

contentSize of your bottomScrollView should have been changed after you set it with code. 使用代码设置后,bottomScrollView的contentSize应该已更改。 Try to move the code setting contentSize of bottomScrollView to viewWillAppear: 尝试将bottomScrollView的代码设置contentSize移动到viewWillAppear:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM