【问题标题】:UITableView pushes up footerview with uitextfield in it when uitextfield is activated当uitextfield被激活时,UITableView会向上推带有uitextfield的footerview
【发布时间】:2015-03-15 03:44:14
【问题描述】:

我的 uitableview 中有一个页脚视图,其中有一个 uitextfield。问题是,当用户单击 uitextfield 时,它会向上推 uitextfield(这没关系),但是在页脚视图和键盘之间存在一个尴尬的间隙。这是一张图片来说明我在说什么。

发生这种情况的任何原因?

以下是相关代码:

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

    return 50;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{


    MSChatFooter *footer = [[[NSBundle mainBundle] loadNibNamed:@"MSChatFooter" owner:self options:nil] firstObject];

    return footer;


}

【问题讨论】:

    标签: ios uitableview


    【解决方案1】:

    这还没有完全测试,但我认为你需要这样的东西

    @property (strong, nonatomic) MSChatFooter *chatFooter;
    
    - (void)viewDidLoad
    {
        //Table Initialization
        ...
    
        chatFooter = [[[NSBundle mainBundle] loadNibNamed:@"MSChatFooter" owner:self options:nil] firstObject];
        UIView *footerView = [UIView new];
        footerView.frame = chatFooter.frame;
        [footerView addSubview:chatFooter];
    
        self.tableView.tableFooterView = footerView;
    
        [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardWasShown:)
                                             name:UIKeyboardDidShowNotification
                                           object:nil];
    }
    
    - (void)keyboardWasShown:(NSNotification *)notification
    {
    
        // Get the size of the keyboard.
        CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    
        //Given size may not account for screen rotation
        int height = MIN(keyboardSize.height,keyboardSize.width);
        int width = MAX(keyboardSize.height,keyboardSize.width);
    
        self.tableView.frame = CGRectMake(0, 0, self.view.bounds.width, self.view.bounds.height - height);
    }
    

    感谢Get the frame of the keyboard dynamically 获取键盘代码

    【讨论】:

      猜你喜欢
      • 2011-07-08
      • 1970-01-01
      • 2013-08-01
      • 2012-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-26
      • 1970-01-01
      相关资源
      最近更新 更多