Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ios6 AutoLayout Support #17

Open
bassrock opened this issue Sep 26, 2012 · 4 comments
Open

ios6 AutoLayout Support #17

bassrock opened this issue Sep 26, 2012 · 4 comments

Comments

@bassrock
Copy link
Contributor

It seems that the view does not resize properly when using ios 6 and auto layout.

@jaytrixz
Copy link

jaytrixz commented Oct 6, 2012

I have the same issue too.

@kinoli
Copy link

kinoli commented Feb 6, 2013

me 2

@rtamesis
Copy link

It is really an issue between UIScrollView and autolayout. One way to reduce (not totally eliminate) it is by adding a UIView as a subview to the scrollview. You can then put your objects in the UIView and expect a more normal autolayout behavior.

@sakuraehikaru
Copy link

I'm not sure if I understand this issue, but I am using iOS 6 with Autolayout in Storyboard, and I get extra space at the bottom after the keyboard is dismissed. Also, using a tab bar controller and going back and forth between different views also seems to mess up the scrollview's scroll position and content size.

I fixed all of these problems by using the following implementation:

Setup these properties in the view controller that contains the TPKeyboardAvoidingScrollView

@property (weak, nonatomic) IBOutlet TPKeyboardAvoidingScrollView *scrollView;

// Subview of the scrollview that holds all your textfields, labels, etc
@property (weak, nonatomic) IBOutlet UIView *formView;

// Stores current scroll position
@property (nonatomic) CGPoint scrollOffset;

Implement these methods in the view controller that contains the TPKeyboardAvoidingScrollView

- (void)viewDidAppear:(BOOL)animated {

    [super viewDidAppear:animated];

    // Set and enable scrollable area
    [self.scrollView setContentSize:self.formView.frame.size];

    // Load last remembered scroll position
    self.scrollView.contentOffset = self.scrollOffset;
}


- (void)viewDidDisappear:(BOOL)animated {

    [super viewDidDisappear:animated];

    // Store current scroll position when leaving this view
    self.scrollOffset = self.scrollView.contentOffset;

    // Reset content offset to fix TPKeyboardAvoidingScrollView and Autolayout incompatibilities,
    // and prevent the content subview from going outside the scrollview and its scrollable area
    self.scrollView.contentOffset = CGPointZero;
}

Replace a line of code for method "keyboardWillHide" in TPKeyboardAvoidingScrollView.m

Change...

self.contentInset = _priorInset;

to...

self.contentInset = UIEdgeInsetsMake(_priorInset.top, _priorInset.left, 0, _priorInset.right);

Doing some NSLog debugging showed that the scrollview's bottom inset remains at 162 after the keyboard is dismissed, thus we get the extra space at the bottom.

Now, everything is working as expected. I can place a view of any height inside the scrollview, and have it scroll and show/hide keyboard beautifully. I can also navigate through navigation controller stacks, or switch views using the tab bar controller, and it won't mess up the scrollview.

I am not an expert programmer by any means, so I could be wrong about whether TPKeyboardAvoiding is compatible with Autolayout, as well as many other things. Please kindly let me know if I've done anything poorly.

Big thanks to Michael Tyson, I love your API's and The Amazing Audio Engine!

P.S. I have yet to test this on iOS 7, iPad, and landscape orientation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants