Exia
Exia

Reputation: 2551

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. 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.

However, the result is quite strange, the bottomScrollView still can be scrolled viertically as the following image shows.(this is not the bounce) enter image description here

Acutally, I tried add a scrollview programly and it works correct. Why this happens? Any bugs of storyboard?

Upvotes: 0

Views: 61

Answers (2)

Exia
Exia

Reputation: 2551

Set NO to self.automaticallyAdjustsScrollViewInsets property, then the scrollview won't show such a "strange" offset

Upvotes: 1

Simon
Simon

Reputation: 237

contentSize of your bottomScrollView should have been changed after you set it with code. Try to move the code setting contentSize of bottomScrollView to viewWillAppear:

Upvotes: 0

Related Questions