iOS11没有正确地约束 [英] iOS11 not taking constraints correctly

查看:221
本文介绍了iOS11没有正确地约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在商店有一个应用程序,为了支持所有设备和键盘,我根据键盘高度更改底部约束高度。它适用于除iOS11之外的所有iOS版本。按钮没有改变它的位置,如下图所示。

I have an app on the store, in order to support all devices and keyboard I am changing the bottom constraint height according to keyboard height. It is working on all iOS versions except on iOS11. The button is not changing its place as it is shown in the below pictures.

谢谢!

这个是iOS10预览

this is iOS10 preview

这是iOS11预览

this is iOS11 preview

代码

    func keyboardWillShow(notification: NSNotification) {
    if !keyboardIsHidden{
        return;
    }
    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
        keyboardIsHidden = false
        nextButtonBottmConstraint.constant = nextButtonBottmConstraint.constant + keyboardSize.height
    }
}


推荐答案

如果您使用 UIKeyboardWillShowNotification 来获取键盘高度,请使用 UIKeyboardFrameEndUserInfoKey UIKeyboardFrameBeginUserInfoKey c $ c>

If you are using UIKeyboardWillShowNotification to get the keyboard height then change UIKeyboardFrameBeginUserInfoKey with UIKeyboardFrameEndUserInfoKey


UIKeyboardFrameBeginUserInfoKey为iOS中的键盘矩形高度
返回0 11.将其更改为UIKeyboardFrameEndUserInfoKey可能为
解决此问题。

UIKeyboardFrameBeginUserInfoKey returns 0 for keyboard rect height value in iOS 11. Changing it to UIKeyboardFrameEndUserInfoKey might solve this issue.

Objective-C

- (void)keyboardWasShown:(NSNotification*)aNotification {
    NSDictionary* info = [aNotification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    //Change constraints
}

Swift 3

func keyboardWasShown(_ aNotification: Notification) {
    let info = aNotification.userInfo
    let kbSize: CGSize? = info?[UIKeyboardFrameEndUserInfoKey]?.cgRectValue?.size
    //Change constraints
}

这篇关于iOS11没有正确地约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆