屏幕旋转后,updateViewConstraints()调用两次

时间:2015-08-17 05:34:21

标签: ios custom-keyboard

我正在实现自定义ios键盘。我在旋转屏幕时遇到键盘视图更新问题。问题是更新动画不流畅(视图大小和位置改变几次)。我认为这是因为updateViewConstraints()方法在轮换后调用了两次。在我的覆盖方法updateViewConstraints()中,我删除并添加键盘高度约束。

let portraitHeight:CGFloat = UIDevice.currentDevice().userInterfaceIdiom == .Pad ? 315 : 264
let landscapeHeight:CGFloat = UIDevice.currentDevice().userInterfaceIdiom == .Pad ? 420 : 200
var heightConstraint: NSLayoutConstraint!
override func updateViewConstraints() {
    super.updateViewConstraints()

    if (self.view.frame.size.width == 0 || self.view.frame.size.height == 0) {
        return
    }

    let isLandscape =  !(self.view!.frame.size.width == self.screenWidth * ((self.screenWidth < self.screenHeight) ? 1 : 0) + self.screenHeight * ((self.screenWidth > self.screenHeight) ? 1 : 0))

    self.inputView!.removeConstraint(self.heightConstraint)
    if (isLandscape) {
        self.heightConstraint.constant = self.landscapeHeight;
        self.inputView!.addConstraint(self.heightConstraint)
    } else {
        self.heightConstraint.constant = self.portraitHeight;
        self.inputView!.addConstraint(self.heightConstraint)
    }
}

旋转屏幕时updateViewConstraints()调用两次是否可以?如何在屏幕旋转上实现平滑动画?

感谢您的任何进展!

0 个答案:

没有答案