0
我有一個滾動視圖設置,當鍵盤出現時(文本框活動)向上推視圖,但它似乎完美地在模擬器中工作,並且每時每刻在實際設備上工作。scrollView.scrollRectToVisible()僅適用於模擬器?
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)
}
}
}
看來它只是不想要工作在設備上,生病試圖找出它,我已經嘗試過這個框架第一,但它不斷推動我的佔位符文本左上角。 – Haidous