我一直在使用键盘通知没有任何问题,并获得键盘的准确高度.
- (void)keyboardDidShow:(NSNotification *) notification{
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
NSLog(@"%f",keyboardSize.height);}
Run Code Online (Sandbox Code Playgroud)
但是在iOS 11中,调用通知时键盘的大小为0.
这种情况下出现的问题是什么?我正在使用xcode 9 Beta 5
我用了 :
NotificationCenter.default.addObserver(self, selector:#selector(keyboardWillShow), name: .UIKeyboardWillShow, object: nil)
@objc func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
let keyboardHeight : Int = Int(keyboardSize.height)
print("keyboardHeight",keyboardHeight)
KeyboardHeightVar = keyboardHeight
}
}
Run Code Online (Sandbox Code Playgroud)
进行更改以获取键盘的高度,但高度不包括建议栏。如何获得键盘高度加上建议栏高度的值?
我想得到( )和( )Keyboard上的高度。AndroidiOSXamarin Forms
当Screen显示有Portraitmode和Landscapemode时,如何获取height值?
我找到了Swift关于的参考资料iOS:
不过可以给我源代码吗Xamarin
以及如何获得键盘的高度Android?
请帮我!
键盘出现时,我的UIView不能正常移动。我用来输入文本的UIView中有一个UITextView。如果我选择TextView输入文本,则会出现键盘,但UIView不会第一次移动。如果我点击背景并使键盘消失,然后再次点击TextView,则UIView会正确向上移动。有人知道这里发生了什么吗?
class ChatViewController: UIViewController, CNContactPickerDelegate, UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource, UIToolbarDelegate, UITextFieldDelegate, UITextViewDelegate {
@IBOutlet weak var composeTextView: UITextView!
@IBOutlet weak var composeViewBottomConstraint: NSLayoutConstraint!
override func viewDidLoad() {
super.viewDidLoad()
composeTextView.delegate = self
}
func textViewDidBeginEditing(_ textView: UITextView) {
UIView.animate(withDuration: 0.5){
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillShow), name: .UIKeyboardWillShow, object: nil)
}
self.view.layoutIfNeeded()
}
@objc func keyboardWillShow(notification: Notification) {
let keyboardSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue
let keyboardHeight = keyboardSize?.height
if #available(iOS 11.0, *){
self.composeViewBottomConstraint.constant = keyboardHeight! - view.safeAreaInsets.bottom
}
else {
self.composeViewBottomConstraint.constant = view.safeAreaInsets.bottom
}
self.view.layoutIfNeeded() …Run Code Online (Sandbox Code Playgroud) ios ×4
keyboard ×2
swift ×2
constraints ×1
height ×1
iphone ×1
objective-c ×1
xamarin ×1
xamarin.ios ×1