我有一个滚动视图设置,当键盘显示时(文本字段处于活动状态)向上推视图但它似乎在模拟器中完美地工作,并且在实际设备上不时地工作。 / p>
func keyboardWasShown(notification: NSNotification){
self.scrollView.isScrollEnabled = true
var info = notification.userInfo!
let keyboardSize = (info[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.size
let contentInsets : UIEdgeInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize!.height, 0.0)
self.scrollView.contentInset = contentInsets
self.scrollView.scrollIndicatorInsets = contentInsets
var aRect : CGRect = self.view.frame
aRect.size.height -= keyboardSize!.height
if let activeField = self.activeField {
if (!aRect.contains(activeField.frame.origin)){
self.scrollView.scrollRectToVisible(activeField.frame, animated: true)
}
}
}
答案 0 :(得分:0)
The answer is no, it should work both in simulator and device.
But i would advise you instead of creating a lot of logic to understand when the view should go up or down to use this framework instead: