Objective c 调整UITextView动画的高度

Objective c 调整UITextView动画的高度,objective-c,swift,uitextview,uiviewanimation,Objective C,Swift,Uitextview,Uiviewanimation,我试图在键盘显示上调整UITextView的大小。然而,我下面的代码行为异常。文本视图跳转到新高度,然后设置动画返回到其原始高度。这里的任何帮助都将不胜感激 //Handles keyboard appearance func keyboardWillShow(notification:NSNotification){ var rightButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem

我试图在键盘显示上调整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)
    }
//处理键盘外观
func键盘将显示(通知:NSNotification){
var rightButton=UIBarButtonItem(barButtonSystemItem:UIBarButtonSystemItem.Done,目标:self,操作:选择器(“dismissKeyboard”))
self.navigationItem.rightBarButtonItem=rightButton
self.origNoteFrame=notes.frame
var duration=NSTimeInterval((通知.userInfo![UIKeyboardAnimationDurationUserInfoKey]作为NSNumber).intValue)
var options=ui视图动画选项(

UInt((notification.userInfo![UIKeyboardAnimationCurveUserInfo]作为NSNumber)。integerValue我通过调整滚动插入而不是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!)
        }
    }

我已经运行了你的代码,但我没有看到这样的行为(而是这里提到的另一个问题。在没有动画的情况下,通过简单地执行
self.notes.frame=CGRectMake(self.notes.frame.origin.x,self.notes.frame.origin.y,self.notes.frame.width,(notification.userInfo?[UIKeyboardFrameEndUserInfoKey]作为NSValue)。CGRectValue().origin.y-10)
?@abinop是的。高度仍然返回到原始高度。