title: changing height of a custom keyboard when rotating
body: <p>I have a customized keyboard created by code, it is a unique input view for a specific textfield. I implement this in my project:</p>
  <pre class="lang-swift prettyprint-override"><code>let keyboardContainerView = KBContainerView(frame: CGRect(x: 0.0, y: 0.0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height*0.5))
  keyboardContainerView.addSubview(myKeyboardView)
  textfield.inputView = keyboardContainerView
  </code></pre>
  <p>The KBContainerView is a UIView but has a function, that is when detected device rotation, the frame change. It's quite simple.</p>
  <pre class="lang-swift prettyprint-override"><code>override init(frame: CGRect) {
      super.init(frame: frame)
      NotificationCenter.default.addObserver(self, selector: #selector(updateFrame), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
  }
  
  required init?(coder aDecoder: NSCoder) {
      super.init(coder: aDecoder)
  }
      
  @objc func updateFrame() {
      self.frame = CGRect(x: 0.0, y: 0.0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height*0.5)
  }
  </code></pre>
  <p>But I found that though the keyboard container view is changed, as I printed it on the command line but the size of keyboard seems does not change. Here is a gif.</p>
  <p><a href="https://i.stack.imgur.com/In2BD.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/In2BD.gif" alt="Portrait" /></a></p>
  <p>Start from a landscape view does not change the height either.</p>
  <p><a href="https://i.stack.imgur.com/prr47.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/prr47.gif" alt="Landscape" /></a></p>
  <p>To fix this problem I tried to use <code>autoresizingMasks</code> on the input view but things get worse,  the keyboard height is wrong when starts the app. The navigation bar also covered keyboard in landscapeview.</p>
  <p><a href="https://i.stack.imgur.com/zTYo5.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zTYo5.gif" alt="Adding the autoresizingMasks" /></a></p>
  <p>In my project, I <strong>did not</strong> wrote a <code>UIKeyboardviewController</code> for simplicity. What I am trying to achieve is that when rotating my device, the keyboard can <strong>takes half space of the screen. (height is 0.5 * screen height)</strong></p>
  <p>Is it because I wrote the change size action in the wrong place?</p>