简体   繁体   English

Swift:出现键盘时,UIView更改了大小

[英]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. 故事板上的“我的视图”的视图高度为215,可以向上滑动至400高度,也可以从400向下滑动至215。

This View has a View which is auto layout 0,0,0,0. 该视图具有自动布局为0,0,0,0的视图。 In this view i load the xib file. 在此视图中,我加载了xib文件。

The xib file contains the arrowImage, UIView, "or" label, and 2 buttons. xib文件包含arrowImage,UIView,“或”标签和2个按钮。

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. xib中的UIView包含textFields和Labels,其高度设置为0,因为它不应在开始时显示,而仅在向上滑动时才显示。

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. 现在向上滑动,我将情节提要中的“视图”调整为400,在内部,我从包含“文本字段”的笔尖调整视图的大小。

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. 它在情节提要中将“视图”的大小调整为215,但我不知道为什么会发生这种情况。

Gif to see whats happens: Gif看看会发生什么:

GIF 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. 在查看了最多的gif信息后,我无需检查代码即可说出,但我建议的一些解决方案是,当您单击文本字段时使用特定约束的标识符来更改约束,或者删除约束并通过代码实现所有功能。

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! 希望这是您的情况!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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