iOS11 not taking constraints correctly(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
来获取键盘高度,然后将 UIKeyboardFrameBeginUserInfoKey
更改为 UIKeyboardFrameEndUserInfoKey代码>
If you are using UIKeyboardWillShowNotification
to get the keyboard height then change UIKeyboardFrameBeginUserInfoKey
with UIKeyboardFrameEndUserInfoKey
UIKeyboardFrameBeginUserInfoKey 为键盘矩形高度返回 0iOS 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
}
斯威夫特 3
func keyboardWasShown(_ aNotification: Notification) {
let info = aNotification.userInfo
let kbSize: CGSize? = info?[UIKeyboardFrameEndUserInfoKey]?.cgRectValue?.size
//Change constraints
}
这篇关于iOS11 没有正确接受约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS11 没有正确接受约束


基础教程推荐
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01