2014-09-23 3 views
0

키보드 쇼에서 UITextView의 크기를 조정하려고합니다. 그러나 아래 코드는 이상하게 작동합니다. 텍스트보기는 새 높이로 점프 한 다음 원래 높이로 다시 애니메이션합니다. 여기에 어떤 도움을 주시면 감사하겠습니다.UITextView의 높이 조절 애니메이션

//Handles keyboard appearance 
    func keyboardWillShow(notification:NSNotification){ 
     var rightButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: Selector("dismissKeyboard")) 
     self.navigationItem.rightBarButtonItem = rightButton 
     self.origNoteFrame = notes.frame 
     var duration = NSTimeInterval((notification.userInfo![UIKeyboardAnimationDurationUserInfoKey] as NSNumber).intValue) 
     var options = UIViewAnimationOptions(
      UInt((notification.userInfo![UIKeyboardAnimationCurveUserInfoKey] as NSNumber).integerValue << 16) 
     ) 
     UIView.animateWithDuration(
      duration, 
      delay: 0.0, 
      options: options, 
      animations: { 
       self.notes.frame = CGRectMake(self.notes.frame.origin.x, self.notes.frame.origin.y, self.notes.frame.width, (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as NSValue).CGRectValue().origin.y - 10) 
      }, 
      completion: nil) 
    } 
+0

내가 당신의 코드를 실행하고 나는 그런 행동이 (오히려 또 다른 문제는 여기에 언급이 표시되지 않습니다 http://stackoverflow.com/questions/26004080/keyboardwillshow-will-only-work-from-the-second -time-on. 애니메이션을 사용하지 않고, 단순히'self.notes.frame = CGRectMake (self.notes.frame.origin.x, self.notes.frame.origin.y, self.notes.frame. 너비는 (notification.userInfo? NSValue로 UIKeyboardFrameEndUserInfoKey) .CGRectValue(). origin.y - 10)'? – abinop

+0

@abinop 예, 그렇습니다. 높이가 여전히 원래 높이로 돌아갑니다. – steventnorris

답변

0

이 문제는 UITextView의 높이와 반대로 스크롤 인세 트를 조정하여 해결되었습니다.

//Handles keyboard appearance 
    func keyboardWillShow(notification:NSNotification){ 

     //Set up done button 
     self.origRightBtn = self.navigationItem.rightBarButtonItem 
     var rightButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: Selector("dismissKeyboard")) 
     self.navigationItem.rightBarButtonItem = rightButton 

     //Move scrolling insets 
     var info:Dictionary = notification.userInfo! 
     var rect:CGRect = self.view.convertRect((info[UIKeyboardFrameBeginUserInfoKey] as NSValue).CGRectValue(), fromView: nil) 
     var insets:UIEdgeInsets = UIEdgeInsets(top: 0.0, left: 0.0, bottom: rect.size.height - 150, right: 0.0) 
     self.notes.contentInset = insets 
     self.notes.scrollIndicatorInsets = insets 
     var newRect:CGRect = self.view.frame 
     newRect.size.height -= rect.height - 150 

     //Scroll to selected range 
     if(selectedRange != nil) 
     { 
      self.notes.scrollRangeToVisible(selectedRange!) 
     } 
    }