显示键盘时,弹出窗口内的UIScrollView内的UITextView不完全可见

时间:2013-05-10 09:46:27

标签: ios uiscrollview uitextview uikeyboard uipopover

我的UIPopover内有UIScrollView,其底部包含UITextView。当键盘显示时,弹出窗口会在文本视图开始编辑时调整大小。我想要下面的代码以确保文本视图可见:

- (void)textViewDidBeginEditing:(UITextView *)textView {

    CGRect visRect = textView.frame;
    [self.scrollView scrollRectToVisible:visRect animated:NO];

}

问题是代码不会使整个文本视图可见。相反,只显示光标底部的文本视图,如下所示:

enter image description here

如何显示整个文本视图/将滚动视图滚动到底部?我试过这个:

CGPoint bottomOffset = CGPointMake(0, self.scrollView.contentSize.height - self.scrollView.bounds.size.height);
[self.scrollView setContentOffset:bottomOffset animated:YES];

in this answer所述,但没有任何作用。

此外,我的滚动视图滚动到键盘移动到位后显示的位置。理想情况下,我希望在键盘移动之前或期间进行滚动。

任何帮助都会很棒。

2 个答案:

答案 0 :(得分:1)

@hey Dave

这是默认情况下UIPopOverController的个案,只要我们使用UIPopOverControler显示任何PopUpView,并假设PopUpView身高可以覆盖KeyBoard 1}}然后在那种情况下PopOverView自动收缩自己。当你重新签名键盘时,PopUpView会自动扩展。我遇到了同样的情况。

这只是我的意见,您可以更改CurrentView(parentView of PopUpView)的来源,因为键盘会显示/隐藏,以便PopUpView能够正确显示自己,并且可以获得适当的空间。

见下文UITextView的委托方法是否作为编辑开始和结束回复。

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
 //chnage the OriginY of PopUpView's SUperView
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{  
 //re Adjust the OriginY of PopUpView's SUperView
}

我希望它对你有帮助。

答案 1 :(得分:1)

我找到了解决方案:

- (void)keyboardDidShow:(NSNotification *)notification {
NSLog(@"Notification: %s", __PRETTY_FUNCTION__ );
//
CGFloat textviewBottom = CGRectGetMaxY(self.commentsTextView.frame);
CGRect belowTextViewRect = CGRectMake(0, textviewBottom, 350.f, self.scrollView.contentSize.height - textviewBottom);
// NB! This works ONLY: 1) keyboardDidShow 2) Non-animated;
// Does NOT work: 1) animated, 2) keyboardWillShow, 3) textViewDidBeginEditing
[self.scrollView scrollRectToVisible:belowTextViewRect animated:NO];
}