Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollview Autolayout Issue

I have a problem with autolayout(maybe) and my scrollview!

My Problem

  1. I scroll down View

2.Then I push to another View

3.Then I go back and the scrollview looks like that and I'm not able to scroll to the highest point.(I see it in the bouncing of the scrollview) Scrollview

Can anybody help me?

like image 748
Mathias Aichinger Avatar asked Sep 25 '12 09:09

Mathias Aichinger


People also ask

What is Autolayout in Swift?

Auto Layout constraints allow us to create views that dynamically adjust to different size classes and positions. The constraints will make sure that your views adjust to any size changes without having to manually update frames or positions.

What is the use of Autolayout?

Auto Layout defines your user interface using a series of constraints. Constraints typically represent a relationship between two views. Auto Layout then calculates the size and location of each view based on these constraints. This produces layouts that dynamically respond to both internal and external changes.


2 Answers

The following code snippet in the containing view controller also seems to solve the problem, without relying on explicit sizes:

- (void)viewDidDisappear:(BOOL)animated {   [super viewDidDisappear:animated];   self.mainScrollView.contentOffset = CGPointZero; } 

It does reset the content offset to the origin, but it seems that so do the other answers.

like image 191
user1071136 Avatar answered Oct 10 '22 06:10

user1071136


if you are still searching for an answer i found it today after two days of headbanging the wall. I will just paste you the code, but the most important thing is when you load your scrollView..

    -(void)viewWillAppear:(BOOL)animated{      [scrollView setFrame:CGRectMake(0, 0, 320, 800)]; }  -(void)viewDidAppear:(BOOL)animated {     [scrollView setScrollEnabled:YES];     [scrollView setContentSize:CGSizeMake(320, 800)];  } 

all this is loaded before -(void)viewDidLoad

notice the height is in both instances 800, which is crucial for resolving this problem. good luck with your project ;)

like image 40
kadore Avatar answered Oct 10 '22 06:10

kadore