1
votes

I am implementing this method to reposition a UIScrollView to show a UITextField that becomes obscured by the keyboard pop-up :

Move a view up only when the keyboard covers an input field

The scrollview is not being moved from the bottom by the keyboard height as expected. The variable 'keyboardSize!.height' is receiving the correct height value, and if I enter random values to the 'bottom' parameter I get the same result. However, if I add values to the 'top' and 'left' parameters they DO move the scrollview when the keyboardWasShown function is called.

let contentInsets : UIEdgeInsets = UIEdgeInsets(top : 0.0, left : 0.0, bottom : keyboardSize!.height, right : 0.0)
self.scrollView.contentInset = contentInsets
self.scrollView.scrollIndicatorInsets = contentInsets

I've had this working fine with a TableViewController but not with the UIScrollView. In this case the UIViewController has a UIView and a UIScrollView layered above it. Any help appreciated.

* Edit *

The issue was a result of ambiguous contraints in the IB. After resetting them and using suggested constraints, the UIScrollView worked correctly. Originally the top constraint was set in relation to the UINavigationBar and not to the top of the view.

1

1 Answers

0
votes

you need to scroll the textfield up past the keyboard in the scrollview

  CGRect visibleRect = CGRect(x: self.view.frame.origin.x, y: self.view.frame.origin.y, width: self.view.frame.size.width, height: self.view.frame.size.height - keyboardSize?.height ?? 0);

  [scrollView setContentOffset:visibleRect.center animated:YES];