如何在键盘存在时使UITextView向上移动 [英] How to make a UITextView move up when keyboard is present

查看:82
本文介绍了如何在键盘存在时使UITextView向上移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您开始输入某个值时,如何向上和向下移动 UITextView 。就像在TextField中一样,我们使用它的委托方法。如果 UITextView 怎么办?

How to move UITextView Up and Down when you start entering some value. Like in TextField we use its delegate method. What to do in case of UITextView ?

推荐答案

编辑完整视图时会向上移动并在完成后编辑将向下移动...

While editing complete View will move up and after done editing will move down...

- (void)textViewDidBeginEditing:(UITextView *)textView
{
   [self animateTextView: YES];
 }

- (void)textViewDidEndEditing:(UITextView *)textView
 {
   [self animateTextView:NO];
  }

- (void) animateTextView:(BOOL) up
    {
        const int movementDistance =heightKeyboard; // tweak as needed
        const float movementDuration = 0.3f; // tweak as needed
        int movement= movement = (up ? -movementDistance : movementDistance);
        NSLog(@"%d",movement);

        [UIView beginAnimations: @"anim" context: nil];
        [UIView setAnimationBeginsFromCurrentState: YES];
        [UIView setAnimationDuration: movementDuration];
        self.view.frame = CGRectOffset(self.inputView.frame, 0, movement);
        [UIView commitAnimations];
    }

我希望这会对你有帮助......

I hope this will help you...

这篇关于如何在键盘存在时使UITextView向上移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆