<legend id='BYC7d'><style id='BYC7d'><dir id='BYC7d'><q id='BYC7d'></q></dir></style></legend>
  • <i id='BYC7d'><tr id='BYC7d'><dt id='BYC7d'><q id='BYC7d'><span id='BYC7d'><b id='BYC7d'><form id='BYC7d'><ins id='BYC7d'></ins><ul id='BYC7d'></ul><sub id='BYC7d'></sub></form><legend id='BYC7d'></legend><bdo id='BYC7d'><pre id='BYC7d'><center id='BYC7d'></center></pre></bdo></b><th id='BYC7d'></th></span></q></dt></tr></i><div id='BYC7d'><tfoot id='BYC7d'></tfoot><dl id='BYC7d'><fieldset id='BYC7d'></fieldset></dl></div>
    <tfoot id='BYC7d'></tfoot>
    • <bdo id='BYC7d'></bdo><ul id='BYC7d'></ul>

      1. <small id='BYC7d'></small><noframes id='BYC7d'>

      2. 出现键盘时移动具有自动布局约束的文本字段

        时间:2023-09-11
          <tfoot id='OC9nh'></tfoot><legend id='OC9nh'><style id='OC9nh'><dir id='OC9nh'><q id='OC9nh'></q></dir></style></legend>

                <bdo id='OC9nh'></bdo><ul id='OC9nh'></ul>
                <i id='OC9nh'><tr id='OC9nh'><dt id='OC9nh'><q id='OC9nh'><span id='OC9nh'><b id='OC9nh'><form id='OC9nh'><ins id='OC9nh'></ins><ul id='OC9nh'></ul><sub id='OC9nh'></sub></form><legend id='OC9nh'></legend><bdo id='OC9nh'><pre id='OC9nh'><center id='OC9nh'></center></pre></bdo></b><th id='OC9nh'></th></span></q></dt></tr></i><div id='OC9nh'><tfoot id='OC9nh'></tfoot><dl id='OC9nh'><fieldset id='OC9nh'></fieldset></dl></div>

                  <tbody id='OC9nh'></tbody>

                  <small id='OC9nh'></small><noframes id='OC9nh'>

                  本文介绍了出现键盘时移动具有自动布局约束的文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个搜索栏文本字段和一个表格视图(用于谷歌自动完成),当键盘进入视图时,我想翻译它们.我成功地做到了这一点,但是,我收到了关于我的约束的警告/错误.我在此视图上通过情节提要使用自动布局,并尝试在显示/隐藏键盘之前/之后禁用/启用约束,但我仍然收到这些错误.我没有正确禁用自动布局吗?我遵循了 this SO回应.

                  I have a search bar text field and a table view (for google auto complete) that I would like to translate up when the keyboard comes into view. I am successfully doing this, however, I am getting warnings/errors about my constraints. I am using auto layout via storyboard on this view and tried to disable/enable the constraints prior to/after showing/hiding the keyboard, but I am still getting these errors. Am I not disabling auto layout correctly? I followed what was given in this SO response.

                  override func viewDidLoad() {
                      ...
                      NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name:UIKeyboardWillShowNotification, object: nil)
                      NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name:UIKeyboardWillHideNotification, object: nil)
                      ...
                  }
                  func keyboardWillShow(sender: NSNotification) {
                      self.pixieLabel.hidden = true
                      self.searchBar.setTranslatesAutoresizingMaskIntoConstraints(true)
                      self.startingTableView.setTranslatesAutoresizingMaskIntoConstraints(true)
                      self.searchBar.frame.origin.y -= 150
                      self.startingTableView.frame.origin.y -= 150
                  }
                  func keyboardWillHide(sender: NSNotification) {
                      self.pixieLabel.hidden = false
                      self.searchBar.setTranslatesAutoresizingMaskIntoConstraints(false)
                      self.startingTableView.setTranslatesAutoresizingMaskIntoConstraints(false)
                      self.searchBar.frame.origin.y += 150
                      self.startingTableView.frame.origin.y += 150
                  }
                  

                  func keyboardWillShow(sender: NSNotification) {
                      self.pixieLabel.hidden = true
                      self.seachBarTopConstraint.constant -= 150
                      self.searchBar.layoutIfNeeded()
                  }
                  func keyboardWillHide(sender: NSNotification) {
                      self.pixieLabel.hidden = false
                      self.seachBarTopConstraint.constant += 150
                      self.searchBar.layoutIfNeeded()
                  }
                  

                  推荐答案

                  我认为您应该创建 @IBOutlet 对约束的引用,而不是调整 frame 值Interface Builder,然后在您想要为它们设置动画时更改这些约束的 constant 值,然后调用 layoutIfNeeded.据我了解,手动更改视图框架和自动布局的值不会混合使用.

                  Instead of adjusting theframe values, I think you should be creating @IBOutlet references to constraints in Interface Builder and then changing the constant value of those constraints when you want to animate them, followed by a call to layoutIfNeeded. As I understand it, manually changing the values of a view's frame and auto layout don't mix.

                  另外,我不会乱用 setTranslatesAutoresizingMaskIntoConstraints,除非您以编程方式添加约束,在这种情况下,您很可能只是将其设置为 false.

                  Also, I wouldn't mess around with setTranslatesAutoresizingMaskIntoConstraints unless you are adding your constraints programmatically, in which case you're most likely just setting it to false.

                  这篇关于出现键盘时移动具有自动布局约束的文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何防止 AutoLayout 重置视图框架? 下一篇:移除所有影响 UIView 的约束

                  相关文章

                  <small id='y5yja'></small><noframes id='y5yja'>

                1. <tfoot id='y5yja'></tfoot>
                    <bdo id='y5yja'></bdo><ul id='y5yja'></ul>
                  <legend id='y5yja'><style id='y5yja'><dir id='y5yja'><q id='y5yja'></q></dir></style></legend>

                      <i id='y5yja'><tr id='y5yja'><dt id='y5yja'><q id='y5yja'><span id='y5yja'><b id='y5yja'><form id='y5yja'><ins id='y5yja'></ins><ul id='y5yja'></ul><sub id='y5yja'></sub></form><legend id='y5yja'></legend><bdo id='y5yja'><pre id='y5yja'><center id='y5yja'></center></pre></bdo></b><th id='y5yja'></th></span></q></dt></tr></i><div id='y5yja'><tfoot id='y5yja'></tfoot><dl id='y5yja'><fieldset id='y5yja'></fieldset></dl></div>