简体   繁体   中英

Swift: UIView changed size when keyboard appears

Update:

My View on the storyboard has a View which is 215 height and it can be swipe up to 400 height and also swiped down from 400 to 215.

This View has a View which is auto layout 0,0,0,0. In this view i load the xib file.

The xib file contains the arrowImage, UIView, "or" label, and 2 buttons.

The UIView in the xib contains the textFields and the Labels and the height of this is set to 0 because it should not be showed on start, only on swipe up.

Now on swipe up i resize the View in the storyboard to 400 and inside i resize the view from the nib which contains the Textfields.

The Problem now is, when i click into the textfield no matter which one. It resize the View in the storyboard back to 215 and i don't know why this happens.

Gif to see whats happens:

GIF

You should check your constrains, if you are using the assistant editor in your project you are likely to have this kind of problems. After seeing the gif that's the most I can say without checking the code but some solutions I propose are either changing the constrains when you click the textfield using a identifier for the specific constrains or removing the constrains and implementing everything by code.

Here's some code to give you an idea on how to update the constrains:

    view.constraints.forEach({r in

        //Here you check for the specific constrains
        //I suggest you naming similar constrains the same
        if r.identifier == "yourIdentifier" {

            //You change the constrain value
            r.constant = 6

        }

        //Update the view constrains
        view.updateConstraints()
    })

Hope this is your case!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM