当UItextField/TextView iPhone中的键盘向上移动时,滚动视图问题 [英] Scroll view issues when key board moves up in UItextField / TextView iPhone

查看:62
本文介绍了当UItextField/TextView iPhone中的键盘向上移动时,滚动视图问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视图上有一个 scrollview ,因为我具有以下所示的所有子视图

I have a scrollview on my view in that i have all the sub views as shown bellow

UIView

  Scroll View

          1.ImageView
          2.Table view
          3.Text View

√√要在出现/关闭键盘时移动滚动视图,我已在textview委托方法中实现了如下逻辑√√

√√ To move the scroll view when keyboard appears / dismiss I have implemented logic in textview delegate metods as follows √√

- (void)textViewDidBeginEditing:(UITextView *)textView;
{
      //To move the view down 
      [UIView beginAnimations:nil context:NULL];
      [UIView setAnimationDelegate:self];
      [UIView setAnimationDuration:0.3];
      [UIView setAnimationBeginsFromCurrentState:YES];
      scrollView.frame = CGRectMake(scrollView.frame.origin.x, (scrollView.frame.origin.y - 120), scrollView.frame.size.width, scrollView.frame.size.height);
      [UIView commitAnimations];

}


- (void)textViewDidEndEditing:(UITextView *)textView 
{   
      //To move the view down 
      [UIView beginAnimations:nil context:NULL];
      [UIView setAnimationDelegate:self];
      [UIView setAnimationDuration:0.3];
      [UIView setAnimationBeginsFromCurrentState:YES];
      scrollView.frame = CGRectMake(scrollView.frame.origin.x, (scrollView.frame.origin.y + 120), scrollView.frame.size.width, scrollView.frame.size.height);
      [UIView commitAnimations];
}

√√此方法可以帮助通过respcet向上/向下移动视图到键盘

√√ This method helps alot to move the view up/down with respcet to keyboard,

但这是滚动的问题.

用户无法按键盘状态滚动所有视图.视图将滚动到如下所示的某个位置,我们看不到图片/表格的第一列.

如果用户不想在没有键盘的情况下显示第一列/个人资料图片.如何解决问题.

推荐答案

首先将滚动内容设置为

scrollView.contentSize=CGSizeMake(320, 600);

然后在调用textView委托方法时为其中的内容设置动画

and then animate there content when textView delegate method is called like

- (void)textViewDidBeginEditing:(UITextView *)textView;
{  
  [scrollView setContentOffset:CGPointMake(0, 120 ) animated:YES]; 
}

- (void)textViewDidEndEditing:(UITextView *)textView 
{
 [scrollView setContentOffset:CGPointMake(0, 0 ) animated:YES]; 
}

这篇关于当UItextField/TextView iPhone中的键盘向上移动时,滚动视图问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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