How to Use Auto Layout on IOS8 Keyboard Expansion

Trying to make auto layout work with keyboard expansion. I originally thought I would make the buttons programmatic, but then I realized that it was better to do it with xib due to my requirement and multiple screen sizes.

See the screenshot below for the current configuration I have done. Button 2: enter image description here

Button 1 and Application Release: enter image description here

The whole constraint configuration looks like this: enter image description here

All I am trying to do is make sure the button fills the width of the screen. They can expand in width to fit screen sizes and orientations. Somehow I feel like it is not capable of understanding device width. Do I need to specify something for this?



source to share

3 answers

Make sure to set the dimensions of the UIView to viewDidLoad so that it looks something like this:

self.mainView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);


I had the same problem and it worked for me. Your limitations are fine.



You have no limit on the distance between two buttons. Try adding a constraint between buttons for each button.



Ben Flores' answer did the trick for me too, but I had to put the code viewDidLayoutSubviews

. Otherwise, my keyboard will crash and not show up. Swift version 3:

override func viewDidLayoutSubviews() {
    let frameSize = self.view.frame.size
    self.mainView.frame = CGRect(x: 0, y: 0, width: frameSize.width, height: frameSize.height)




All Articles