首次打开应用时,内容在UIScrollView中显示较低

时间:2015-06-28 18:05:49

标签: ios iphone uiscrollview

我的内容位于UIScrollView中嵌入的UIView中,显示的内容低于我第一次打开视图时的内容。

enter image description here

然而,当我点击任何文本字段时,它会向上滚动...

enter image description here

并准确地返回到它应该是

的地方

enter image description here

这是我正在使用的代码:

- (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(肖像)。有什么想法吗?

非常感谢!

0 个答案:

没有答案