【问题标题】:UITextView inside a UIScrollView inside a Popover is not fully visible when keyboard is displayed显示键盘时,Popover 内的 UIScrollView 内的 UITextView 不完全可见
【发布时间】:2013-05-04 23:21:09
【问题描述】:

我有一个UIPopover,里面有一个UIScrollView,底部有一个UITextView。当键盘显示时,弹出框会随着文本视图开始被编辑而调整大小。我希望下面的代码确保文本视图可见:

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

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

}

问题是代码没有使整个文本视图可见。而是只显示直到光标底部的文本视图,如下所示:

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

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

正如in this answer 解释的那样,但没有任何效果。

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

任何帮助都会很棒。

【问题讨论】:

  • 在滚动到 visRect 之前,将 visRects 原点更改为“visRect.origin.y = CGRectGetMaxY(visRect)”。然后滚动到这个矩形。
  • @croyneaus4u。谢谢,很遗憾没有帮助。

标签: ios uiscrollview uitextview uikeyboard uipopover


【解决方案1】:

@嘿戴夫

默认情况下UIPopOverController 的情况下,每当我们使用UIPopOverControler 显示任何PopUpView 并假设PopUpView 的高度与KeyBoard 可以覆盖的一样大,那么在这种情况下@987654326 @ 自动收缩自身。当您退出键盘时,PopUpView 将自动扩展。我遇到了同样的情况。

这只是我的意见,您可以将CurrentView(parentView of PopUpView) 的原点更改为键盘显示/隐藏,以便PopUpView 可以正常显示并获得适当的空间。

见下图是 UITextView 的 Delegate 方法响应编辑开始和结束。

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

希望对你有帮助。

【讨论】:

  • 感谢您的建议。
  • @DaveChambers 至少你应该支持我的努力,如果它真的给了你任何想法的话......!!!! :)
【解决方案2】:

我找到了解决办法:

- (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];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-04
    • 2017-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多