Textview框架变得挤压,无法恢复原状?

时间:2015-06-01 12:01:13

标签: ios objective-c iphone xcode6 uitextview

enter image description here

enter image description here

keyboardWillShow 方法实现:

 - (void)keyboardWillShow:(NSNotification *)notification 
    {

     [UIView beginAnimations:nil context:nil];
     CGRect endRect = [[notification.userInfo 
     objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
      CGRect newRect = txtNotes.frame;
      //Down size your text view
      newRect.size.height -= endRect.size.height;
      txtNotes.frame = newRect;
      [UIView commitAnimations];
    }

keyboardWillHide 方法实现:

  - (void)keyboardWillHide:(NSNotification *)notification
   {
      // Resize your textview when keyboard is going to hide
       UIEdgeInsets contentInsets = UIEdgeInsetsZero;
       txtNotes.contentInset = contentInsets;
       txtNotes.scrollIndicatorInsets = contentInsets;

   }

1 个答案:

答案 0 :(得分:1)

一些事情:

1)META:您应该在每个代码行之前添加4个空格,以使代码正确显示。

2)这看起来像是一个基本的约束问题。您应该检查故事板的Auto Layout