简体   繁体   English

当 UITextView 成为第一响应者时,为什么 UIScrollView 不向上滚动?

[英]Why UIScrollView does not scroll up when UITextView becomes first responder?

UITextView becomes first responder when user taps on a button to add a UITextView on UIScrollView .当用户点击按钮在UIScrollView上添加UITextView时, UITextView成为第一响应者。 Actually UIView which contains UITextView or UITextField is added in UIScrollView .实际上包含UITextViewUITextField UIView 添加在UIScrollView When keyboard appears, scrollview does not scroll up, however UITextField makes it scrolling up when it becomes first responder.当键盘出现时,scrollview 不会向上滚动,但是UITextField使它在成为第一响应者时向上滚动。 I register UIKeyboardDidShowNotification to scroll up.我注册了UIKeyboardDidShowNotification来向上滚动。 Below is my code下面是我的代码

- (void)keyboardDidShow:(NSNotification *)notification {
        CGRect keyboardEndFrame;
        [(notification.userInfo)[UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];

        NSInteger height = CGRectGetHeight(keyboardEndFrame);

        NSInteger lastObj = arrayTotalObjects.count - 1;
        UIView *lastView = [arrayTotalObjects objectAtIndex:lastObj];

        if(!(lastView.frame.origin.y > height))
            return;

        UIEdgeInsets inset = originalInset;
        inset.bottom += height;
        NSLog(@"inset: %f", inset.bottom);

        [UIView animateWithDuration:0.3f animations:^{
            scrlView.contentInset = inset;
        }completion:^(BOOL finished) {
            NSLog(@"scrlView inset bottom: %f", scrlView.contentInset.bottom);
        }];
}

In this case lastView will be UIView containing UITextView.在这种情况下,lastView 将是包含 UITextView 的 UIView。

This code works for UITextField but not for UITextView .此代码适用于UITextField但不适用于UITextView How is that possible?这怎么可能? Is it because UITextView is subclass of UIScrollView ?是因为UITextViewUIScrollView子类吗?

If someone see this question, The answer is set UITextView scrolling enabled false如果有人看到这个问题,答案是 set UITextView scrolling enabled false

In lawicko 's answer, I got a hint.lawicko的回答中,我得到了一个提示。 subclass of UIScrollView . subclass of UIScrollView

It works to me.它对我有用。

In short, the answer to your question is yes, this behavior is caused by UITextView being a subclass of UIScrollView.简而言之,您的问题的答案是肯定的,这种行为是由 UITextView 是 UIScrollView 的子类引起的。 You can find more details, as well as the solution how to disable it, here .您可以在此处找到更多详细信息以及如何禁用它的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当 UITextField 成为第一响应者时,如何使 UIScrollView 自动滚动 - How to make a UIScrollView auto scroll when a UITextField becomes a first responder 当它是第一响应者时,无法在UIScrollView中移动UITextView - Having trouble moving an UITextView in a UIScrollView when it's the first responder UITextView何时/如何成为第一响应者? - When/How does a UITextView become a First Responder? UITextField成为第一响应者后,UITableView不会将单元格滚动到可见 - UITableView does not scroll cell to visible after UITextField becomes first responder InputAccessoryView 中的 UITextView 没有成为第一响应者(键盘最初不显示) - UITextView in InputAccessoryView not becoming First Responder (Keyboard does not show up initially) 成为FirstResponder:自动滚动到成为第一响应者的UIControl - becomeFirstResponder: automatically scroll to the UIControl that becomes first responder UITextView成为第一响应者,但指针没有到达那里 - UITextView becomes first responder but the pointer doesn't go there 如何知道 UITextView 何时成为第一响应者 - How to know when UITextView became first responder UITextView不会成为第一响应者 - UITextView not becoming first responder 在iOS 7上成为第一响应者后,UITextView不会滚动到插入符号 - UITextView doesn't scroll to caret after becoming first responder on iOS 7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM