3

I'm implementing custom ios keyboard. I have an issue with updates of keyboard views when rotating screen. The problem is that animation of update is not smooth (view sizes and positions change few times). I think this happens because updateViewConstraints() method called twice after rotation. In my override method of updateViewConstraints() I remove and add keyboard height constraint.

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)
    }
}

Is this okay that updateViewConstraints() called twice when rotating screen? And how to achieve smooth animation on screen rotation?

Thanks for any advance!

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.