2010-03-30 46 views
3

我有一個包含10個以編程方式創建的UITextFields的視圖。我想要以下行爲:iPhone:定位多個UITextFields當顯示鍵盤和方向更改

  1. 當我點擊一個特定的UITextField時,鍵盤應該隱藏所有可視文本字段下的文本字段。
  2. 如果我有選擇的文本字段並更改設備的方向,文本字段和鍵盤都應該旋轉到正確的方向,而不文本字段失去選擇焦點。
  3. 我需要控制鍵盤上的返回鍵是否處於活動狀態。

如何管理這些文本字段得到這些行爲。

+0

你能不能換一種說法,並使其理解?你想要鍵盤出來? – Rengers 2010-03-30 12:28:18

+0

我有五個基本問題 我有1個View.that視圖有10個UITextfields。這些不是放在xib文件上,而是我寫的代碼。 1>當我點擊UITextfield時,我的鍵盤應該隱藏所有UITextfields,它在我點擊的UITextfield下面 2>如果我點擊UITextfield並按回車,如果我自動旋轉那個視圖,在景觀上應該是一樣的,反之亦然。 3> 如果我點擊的UITextField與按回車鍵,如果我自轉這一觀點無論方式是在縱向視圖應該在landscapevie – user217572 2010-03-30 13:24:21

+0

同樣意味着例如我是在4日的UITextField,當我上的UITextField點擊,鍵盤會隱藏下面的所有文本字段,只有UITextfield會在鍵盤上方。 現在,如果我的觀點是在肖像模式和我切換到橫向模式 – user217572 2010-03-30 13:50:36

回答

0

添加滾動視圖中的文本字段的設置及標籤所有textfield.Than把下面的代碼,你必須application.You需要輸入文本框,你按你的要求的位置。

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { 
// Begin animations to move TextFields into view. 

if (textField.tag == 1) { 

    [UIView beginAnimations: @"moveField" context: nil]; 
    [UIView setAnimationDelegate: self]; 
    [UIView setAnimationDuration: 0.5]; 
    [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; 
    self.scrlview.frame = CGRectMake(0,30,320,357); 
    [UIView commitAnimations]; 
    textfield2.hidden=YES; 
    textfield3.hidden=YES; 
    textfield4.hidden=YES; 



}  

else if(textField.tag == 2) 
{ 

    [UIView beginAnimations: @"moveField" context: nil]; 
    [UIView setAnimationDelegate: self]; 
    [UIView setAnimationDuration: 0.5]; 
    [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; 
    self.scrlview.frame = CGRectMake(0,30,320,357); 
    [UIView commitAnimations]; 
    textfield1.hidden=YES; 
    textfield3.hidden=YES; 
    textfield4.hidden=YES; 


} 

else if(textField.tag == 3) 
{ 

    [UIView beginAnimations: @"moveField" context: nil]; 
    [UIView setAnimationDelegate: self]; 
    [UIView setAnimationDuration: 0.5]; 
    [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; 
    self.scrlview.frame = CGRectMake(0,25,320,357); 
    [UIView commitAnimations]; 
    textfield1.hidden=YES; 
    textfield2.hidden=YES; 
    textfield4.hidden=YES; 


} 

else if(textField.tag == 4) 
{ 

    [UIView beginAnimations: @"moveField" context: nil]; 
    [UIView setAnimationDelegate: self]; 
    [UIView setAnimationDuration: 0.5]; 
    [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; 
    self.scrlview.frame = CGRectMake(0,20,320,357); 
    [UIView commitAnimations]; 
    textfield1.hidden=YES; 
    textfield2.hidden=YES; 
    textfield3.hidden=YES; 


} 


return YES; 

}

//Set the objects on the view when device orientation will change. 
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { 

if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation ==UIInterfaceOrientationLandscapeRight) { 

    // set the views oreintation here for landscapemode.   
} 
if(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || 
    interfaceOrientation == UIInterfaceOrientationPortrait) { 


    //set the views oreintation here for Portraitmode. 
} 

}

//代表呼籲時方向會改變

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Return YES for supported orientations 
return YES; 

}