I
I
IlyaMordasov2016-11-08 21:14:29
iOS
IlyaMordasov, 2016-11-08 21:14:29

How to change keyboard height in swift 3?

How to change keyboard height in swift 3? The task is to make it so that when you press a button on the keyboard, the view is resized to full screen.
I do it through NSLayoutConstraint

var screenWidth = UIScreen.main.bounds.size.width;
var screenHeight = UIScreen.main.bounds.size.height;

var heightConstraint: NSLayoutConstraint?

func setUpHeightConstraint()
    {
        if (heightConstraint == nil)
        {
            heightConstraint = NSLayoutConstraint(item: view, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: screenHeight);
            heightConstraint?.priority = UILayoutPriority(UILayoutPriorityRequired);
            
            view.addConstraint(heightConstraint!);
        }
        else
        {
            heightConstraint?.constant = screenHeight;
        }
        heightConstraint?.constant = screenHeight;
        print(">>: \(view.frame.size)");
    }

the function is called from updateViewConstraints()
As a result, the print prints the old sizes, and the view itself does not change
. The problem is that I already implemented this a month ago, but I was careless to remove that code, and the backups were not saved.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
briahas, 2016-11-17
@briahas

Probably forgot to insert before adding the constraints:

view.translatesAutoresizingMaskIntoConstraints = false

I
IlyaMordasov, 2016-11-17
@IlyaMordasov

Yes, I inserted it, it didn’t really help, or rather, the application behaved strangely, in one assembly, the height changed, then reselected (added print () with text), compiled and again does not change

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question