我的内容位于UIScrollView中嵌入的UIView中,显示的内容低于我第一次打开视图时的内容。
然而,当我点击任何文本字段时,它会向上滚动...
并准确地返回到它应该是
的地方
这是我正在使用的代码:
- (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];
}
}
适用于iPad(风景),但不适用于iPhone(肖像)。有什么想法吗?
非常感谢!