简体   繁体   English

出现键盘时,Textview内部表格页脚视图无法滚动到可见区域

[英]Textview Inside table footer view not scroll to visible area when keyboard appears

I have added one tableview inside xib . 我在xib添加了一个tableview After that I have added headerview and footerview in that. 之后,我在其中添加了headerviewfooterview Inside footerview there is one textview . footerview有一个textview Textview can't scroll to visible area once keyboard appears. keyboard出现后,Textview无法scroll到可见区域。

Let me know anyone facing the same issue. 让我知道遇到同样问题的任何人。

This behavior is not handled by default. 默认情况下不处理此行为。 You have to implement it yourself. 您必须自己实施。

The other solution is to use UITableViewController instead of UITableView , which implements this behavior by default. 另一种解决方案是使用UITableViewController而不是UITableView ,它默认情况下实现了此行为。 You could put the UITableViewController in a UIContainerView if you don't want it to take the whole frame. 如果不希望UITableViewController占用整个框架,则可以将其放在UIContainerView

See code here if you want to implement the behavior yourself How to make a UITextField move up when keyboard is present? 如果您想自己实现该行为,请参见此处的代码如何在有键盘的情况下使UITextField向上移动?

Hope it helps. 希望能帮助到你。

Here is some sample code: 这是一些示例代码:

  #define kOFFSET_FOR_KEYBOARD 80.0

-(void)keyboardWillShow {
    // Animate the current view out of the way
    if (self.view.frame.origin.y >= 0)
    {
        [self setViewMovedUp:YES];
    }
    else if (self.view.frame.origin.y < 0)
    {
        [self setViewMovedUp:NO];
    }
}

-(void)keyboardWillHide {
    if (self.view.frame.origin.y >= 0)
    {
        [self setViewMovedUp:YES];
    }
    else if (self.view.frame.origin.y < 0)
    {
        [self setViewMovedUp:NO];
    }
}

-(void)textFieldDidBeginEditing:(UITextField *)sender
{
    if ([sender isEqual:mailTf])
    {
        //move the main view, so that the keyboard does not hide it.
        if  (self.view.frame.origin.y >= 0)
        {
            [self setViewMovedUp:YES];
        }
    }
}

//method to move the view up/down whenever the keyboard is shown/dismissed

-(void)setViewMovedUp:(BOOL)movedUp
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3]; // if you want to slide up the view

    CGRect rect = self.view.frame;
    if (movedUp)
    {
        // 1. move the view's origin up so that the text field that will be hidden come above the keyboard 
        // 2. increase the size of the view so that the area behind the keyboard is covered up.
        rect.origin.y -= kOFFSET_FOR_KEYBOARD;
        rect.size.height += kOFFSET_FOR_KEYBOARD;
    }
    else
    {
        // revert back to the normal state.
        rect.origin.y += kOFFSET_FOR_KEYBOARD;
        rect.size.height -= kOFFSET_FOR_KEYBOARD;
    }
    self.view.frame = rect;

    [UIView commitAnimations];
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    // register for keyboard notifications
    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardWillShow)
                                             name:UIKeyboardWillShowNotification
                                           object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardWillHide)
                                             name:UIKeyboardWillHideNotification
                                           object:nil];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    // unregister for keyboard notifications while not visible.
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                             name:UIKeyboardWillShowNotification
                                           object:nil];

    [[NSNotificationCenter defaultCenter] removeObserver:self
                                             name:UIKeyboardWillHideNotification
                                           object:nil];
}

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

相关问题 当键盘出现BUG时,将表格视图滚动到顶部 - Scroll table view row to top when keyboard appears BUG 当键盘出现iOS时,横向视图中的textview缩小 - textview shrinking in landscape view when keyboard appears ios 出现键盘时如何使滚动视图在缩小的视图区域中滚动 - How to make the scrollview scrollable in reduced view area when keyboard appears 当键盘显示UITextView而不是同一视图上的UITextField时,滚动视图 - Scroll view when keyboard appears for UITextView, but not for the UITextField that's on the same view 键盘出现时如何在可见框中心移动视图? - How to move view at the center of visible frame when keyboard appears? 如何在键盘出现时使视图控制器滚动到文本字段 - How to make the view controller scroll to text field when keyboard appears 在滚动视图中在textview之外点击时关闭键盘 - Dismiss keyboard when tapped outside of a textview in a scroll view 出现键盘时移动可变高度的文本视图 - Move textview of variable height when keyboard appears 当显示键盘时,表格页脚视图中的UIButton对触摸没有响应 - UIButton in table footer view not responding to touches when keyboard shown 内容插入以在键盘出现时移动表格视图 - content inset to move the table view when keyboard appears
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM