2016-03-10 32 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

您必须更新此代码根据您的需要,我也编辑它,并添加(&&)条件之间 –

相关问题