2012-01-16 28 views
0

我havng一个文本框和两个textViews ...在写入东西在1 conrol键盘被强行...但是当我想转移到另一个控制我的键盘doesn'不要让我写,因为它涵盖了整个视图......我能解决我的问题吗?键盘不会从视图中消失iphone

+0

你的意思是说键盘掩盖了你的文本字段?这是你的问题吗? – 2012-01-16 13:13:04

+0

是的。这也是一个问题 – 2012-01-17 04:16:17

+0

@khushbu,你需要先学习目标的基本知识c。使用[this](http://iphonesdkbasics.blogspot.com/2010/01/disabling-keyboard-on-uitextfield.html )函数来禁用uitextfield的键盘,并通过触摸事件来隐藏uitextview的键盘,因为它不会使用返回键禁用。另外,请尝试[这,我认为这是你会喜欢的。](http:// stackoverflow。 com/questions/1126726/how-to-make-a-uitextfield-move-up-when-keyboard-is-present) – Sarah 2012-01-16 13:10:36

回答

0

提供的UITextView和uitextfiled使用委托功能....

+0

我已经尝试了一件事...我已经采取了我的整个视图上的按钮....所以,每当我点击我的任何部分视图,键盘将消失...我用“ self.resignResponder“...但不工作.....你能以其他方式建议我吗? – 2012-01-16 13:10:32

+1

它应该是[textField resignFirstResponder] – vishy 2012-01-16 13:20:30

+0

而不是self.resign响应者,您必须从uitextfield或uitextview中退出响应者。或使用基于ios的uitextfield或textview检出任何教程.. – Ballu 2012-01-16 13:21:05

0
- (void) animateTextField: (UITextField*) textField up: (BOOL) up 
{ 
    const int movementDistance = 150; // tweak as needed 
    const float movementDuration = 0.3f; // tweak as needed 

    int movement = (up ? -movementDistance : movementDistance); 

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

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{ 

     [self animateTextField: textField up: YES]; 
} 
- (void)textViewDidEndEditing:(UITextView *)textView{ 
      [self animateTextField: textField up: NO]; 

} 
1

你应该将你的观点了,使键盘犯规覆盖文本框/ TextView的。这样的事情...

- (void)textFieldDidBeginEditing:(UITextField *)textField 
{ 
    if (textField == *textFieldName*) 
    { 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDelegate:self]; 
     [UIView setAnimationDuration:0.5]; 
     [UIView setAnimationBeginsFromCurrentState:YES]; 
     self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y - 65.0), self.view.frame.size.width, self.view.frame.size.height); 
     [UIView commitAnimations]; 

    } 
} 

- (void)textFieldDidEndEditing:(UITextField *)textField 
{ 
    if (textField == *textFieldName*) 
    { 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDelegate:self]; 
     [UIView setAnimationDuration:0.5]; 
     [UIView setAnimationBeginsFromCurrentState:YES]; 
     self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y + 65.0), self.view.frame.size.width, self.view.frame.size.height); 
     [UIView commitAnimations]; 
    } 
} 

和TextView的使用:

- (void)textViewDidBeginEditing:(UITextView *)textView 

- (void)textViewDidEndEditing:(UITextView *)textView 
0

你可以改变你的整个视图向上或只是移动控件(文本字段,文本视图)向上..或使您的视图可滚动,以便用户可以向下滚动,而键盘可见。

+0

但键盘覆盖第二个控制器... – 2012-01-17 04:16:59

+0

即使如此..您可以将所有控件添加到滚动视图中,因此如果用户使用键盘滚动屏幕可见他将能够看到其他控件 – 2012-01-17 13:39:29