2016-03-10 57 views
0

我有13個文本字段。我想設置視圖動畫只有4將顯示在文本框底部將UITextField委託設置爲所有UITextField併爲幾個文本字段設置視圖動畫

這裏是我的代碼:

if (textField.editing != ((_GET_companyname)||(_GET_firstname)||(_GET_middlename)||(_GET_lastname)||(_GET_companyurl)||(_GET_streetaddress)||(_GET_postbox)||(_GET_code)||(_GET_phonenum))) 
{ 
    NSLog(@"Entered in condition"); 
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
    { 
     //Keyboard becomes visible 
     [UIView beginAnimations:nil context:NULL]; 
     // [UIView setAnimationDuration:0.25]; 
     self.view.frame = CGRectMake(0,-200,self.view.frame.size.width,self.view.frame.size.height); 
     [UIView commitAnimations]; 
    } 
} 
else 
{ 
    NSLog(@"Entered else Part"); 
} 

我需要下面的設置爲所有14個文本框

-(BOOL) textFieldShouldReturn:(UITextField *)textField{ 
[textField resignFirstResponder]; 
return YES; 
} 
+0

是什麼_GET_companyname和其他人呢? –

+0

那麼問題是什麼? – Andy

+0

我有13個文本字段我想設置文本視圖爲全部設置並將Uiview動畫設置爲4個文本字段@Andy – Jayasabeen

回答

0

你可以使用標籤檢查這些 - (void)viewDidLoad {super viewDidLoad];

UITextField *textFiledName = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 200, 200)]; 
textFiledName.tag = 0; 
textFiledName.delegate = self; 
[self.view addSubview:textFiledName]; 

UITextField *textFiledLastName = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 200, 200)]; 
textFiledLastName.tag = 1; 
textFiledLastName.delegate = self; 
[self.view addSubview:textFiledLastName]; 

}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{ 
if (textField.tag == 0) { 
    //No Animation 
}else if (textField.tag == 1){ 
    //Add Animation 
} 
return YES; 

}

+0

終於工作,如果(textField.tag> 8) { [UIView beginAnimations:nil context:NULL]; // [UIView setAnimationDuration:0.25]; self.view.frame = CGRectMake(0,-200,self.view.frame.size.width,self.view.frame.size.height); [UIView commitAnimations]; } – Jayasabeen

1

根據你,如果「_GET_companyname」是UITextField的IBOutlet。

那麼你應該寫這樣的事情下面

if ((textField != _GET_companyname)&&(textField != _GET_firstname)) // etc 
{ 
    NSLog(@"Entered in condition"); 
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
    { 
     //Keyboard becomes visible 
     [UIView beginAnimations:nil context:NULL]; 
     // [UIView setAnimationDuration:0.25]; 
     self.view.frame = CGRectMake(0,-200,self.view.frame.size.width,self.view.frame.size.height); 
     [UIView commitAnimations]; 
    } 
} 
else 
{ 
    NSLog(@"Entered else Part"); 
} 

編輯: - 而且也不用檢查(=!)。你應該檢查(==)少數UITextFields。那會更好。

+0

即使我執行一個動作在其他部分執行 – Jayasabeen

+0

您必須更新此代碼根據您的需要,我也編輯它,並添加(&&)條件之間 –

相關問題