【问题标题】:TextView Resize according to ContentTextView 根据内容调整大小
【发布时间】:2015-11-04 04:39:26
【问题描述】:

textview 里面有一个视图。固定在桌子底部。我担心的是,当键盘显示视图根据他的内容向上移动时。和键盘隐藏他们根据他的内容隐藏。出现一些问题。它向上移动更多,然后当我们开始在 textview 上写入时,它们向下移动。请帮助,如果它不能解决我的公司解雇我我请求你请帮助。这是我的代码。

    - (void)textViewDidChange:(UITextView *)textView
    {
        CGFloat fixedWidth = textView.frame.size.width;
        CGSize newSize = [textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];
        CGRect newFrame = textView.frame;
        newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height);
        textView.frame = newFrame;
        CGRect frame1 = [UIScreen mainScreen].bounds;
        bottomView.frame=CGRectMake(0, frame1.size.height-keyBoadSize-newSize.height-25, self.view.frame.size.width, newSize.height+25);

    }


- (void)keyboardWasShown:(NSNotification*)aNotification
{
      NSDictionary* info = [aNotification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    keyBoadSize =kbSize.height;

    CGRect keyboardRect = [aNotification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];

              [UIView animateWithDuration:0.2f animations:^{

               if (text.text.length ==0 ]) {
                    bottomView.frame =CGRectMake(0, [[UIScreen mainScreen] bounds].size.height -kbSize.height-60, bottomView.frame.size.width, 60);
               }
               else
               {

               bottomView.frame =CGRectMake(0, [[UIScreen mainScreen] bounds].size.height -kbSize.height-bottomView.frame.size.height, bottomView.frame.size.width, 60);
               }



           [tableViews setContentInset:UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0)];


    }];

}

- (void)keyboardWillBeHidden:(NSNotification*)aNotification

{


    NSDictionary* info = [aNotification userInfo];

    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    keyBoardDownHeight =kbSize.height;

    [UIView animateWithDuration:0.2f animations:^{
                   if (text.text.length ==0) {
                           bottomView.frame =CGRectMake(0,[[UIScreen mainScreen] bounds].size.height - 60 , bottomView.frame.size.width, bottomView.frame.size.height);
            }
            else
            {
                 bottomView.frame =CGRectMake(0,[[UIScreen mainScreen] bounds].size.height -bottomView.frame.size.height-10 , bottomView.frame.size.width, bottomView.frame.size.height);
            }


        [tableViews setContentInset:UIEdgeInsetsZero];

    }];


}

【问题讨论】:

  • 使用这个方法 [tableViews setContentOffset: animated:];而不是 [tableViews setContentInset:];
  • 我的底视图问题。
  • tableview 是底视图吗?
  • 不在表格视图之外
  • 对于你所说的功能……你需要在scrollview中添加tableview和bottom view……然后使用setContentOffset方法:animated:(scrollview的方法)根据键盘行为上下滚动……跨度>

标签: objective-c iphone ios9


【解决方案1】:

使您的视图或表格视图继承自 TPKeyboardAvoiding 类,您的问题将得到解决。

忠告::开发者的工作需要抗压……永远不要惊慌,努力工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-29
    • 2011-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-21
    • 2012-02-09
    • 2010-09-14
    相关资源
    最近更新 更多