I have my content in a UIView embedded in a UIScrollView showing lower than it should when I first open the view.
However, when I then click on any of the textfields, it scrolls up...
And returns exactly to the place where it is supposed to be
This is the code I am using:
- (void)keyboardWasShown:(NSNotification*)aNotification
{
self.info = [aNotification userInfo];
CGSize kbSize = [[self.info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
self.scrollView.contentInset = contentInsets;
self.scrollView.scrollIndicatorInsets = contentInsets;
// If active text field is hidden by keyboard, scroll it so it's visible
// Your app might not need or want this behavior.
CGRect aRect = self.scrollView.frame;
aRect.size.height -= kbSize.height;
CGPoint origin = self.activeField.frame.origin;
origin.y -= self.scrollView.contentOffset.y;
//origin.y += activeField.frame.size.height;
if (!CGRectContainsPoint(aRect, origin) ) {
CGPoint scrollPoint = CGPointMake(0.0, self.activeField.frame.origin.y + self.activeField.frame.size.height - aRect.size.height);
[self.scrollView setContentOffset:scrollPoint animated:YES];
}
}
Works fine for iPad (landscape) but not for iPhone (portrait). Any ideas?
Thanks a lot!
Aucun commentaire:
Enregistrer un commentaire