2012-01-16 30 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