I am trying to move a UIScrollView when the keyboard hides a UITextField by contentInsets using contentInsets as shown.
However, it does not work for keyboard height. The height of the keyboard is 216, but it only stops scrolling in the right place if I set the bottom insert to 515 for iPhone portrait mode and 310 for iPhone landscape mode. Why would these measurements be so different? I do not want to hard code these arbitrary values.
- (void)viewDidLoad { [super viewDidLoad]; self.view.frame = self.parentViewController.view.frame; [self.textView becomeFirstResponder]; NSLog(@"scrollview: %f,%f, parent: %f,%f", self.view.frame.size.height, self.view.frame.size.width, self.parentViewController.view.frame.size.height, self.parentViewController.view.frame.size.width); [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; } - (void)keyboardWasShown:(NSNotification *)notification { if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone) {
Edit:
Before opening the keyboard, I will print this:
NSLog(@"scrollview: %f,%f, parent: %f,%f", self.view.frame.size.height, self.view.frame.size.width, self.parentViewController.view.frame.size.height, self.parentViewController.view.frame.size.width);
and he prints this:
scrollview: 431.000000,320.000000, parent: 431.000000,320.000000
source share