Reputation: 555
I've got a scroll view setup to push a view upwards when the keyboard shows up (textfield active) but it seems to perfectly work in the simulator, and work every now and then in on an actual device.
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)
}
}
}
Upvotes: 0
Views: 200
Reputation: 662
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:
Upvotes: 1