2013-02-11 2 views
0

텍스트 필드가 6 개 있고 처음 3 개의 텍스트 필드를 위로 이동하지 않습니다.하지만 나머지는 원합니다. 1 텍스트 필드를 클릭하면 이동하지 않지만 2를 클릭하면 , 3 등등 텍스트 필드에서보기가 아래로 이동합니다.애니메이션이있는 텍스트 필드 이동

내가 사용한 코드 : -

- (void) animateTextField: (UITextField*) textField up: (BOOL) up 
{ 

    const int movementDistance = 105; 

    const float movementDuration = 0.3f; 

    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]; 

} 


- (void)textFieldDidBeginEditing:(UITextField *)textField 
{ 

if (textField==txtname) { 

     toolphone.hidden = YES; 
    } 

    if (textField==txtcompanyname) { 
     toolphone.hidden = YES; 
    } 
    if (textField==txtemail) { 
     toolphone.hidden = YES; 

    } 

    if (textField ==txtsubject) { 
     toolphone.hidden = YES; 
    } 

    if (textField ==txtphone) { 
     [txtphone resignFirstResponder]; 
     toolphone.hidden = NO; 
    } 

    if (textField ==txtmessage) { 
     toolphone.hidden = YES; 
     [self animateTextField: textField up: YES]; 
    } 


} 

답변

0

당신은 특정 텍스트 필드에 애니메이션을 수행하기 위해 이름을 텍스트 필드 확인할 수 있습니다.

-(void) animateTextField: (UITextField*) textField up: (BOOL) up 
{ 
    if (textField!=1sttextfieldname||textField!=2ndtextfieldname||textField!=3rdtextfieldname) { 
    const int movementDistance = 105; 

    const float movementDuration = 0.3f; 

    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]; 
    } 
} 
1

func textFieldDidBeginEditing(textField: UITextField) { 
     animateTextField(textField, up: true) 
    } 

func textFieldDidEndEditing(textField: UITextField) { 
     animateTextField(textField, up: false) 
    } 
func animateTextField (textField:UITextField, up:Bool) { 

     var movementDistance = 80 

     var movementDuration = 1.0 
     var movement = CGFloat(up ? -movementDistance : movementDistance) 
     UIView.beginAnimations("anim", context: nil) 
     UIView.setAnimationBeginsFromCurrentState(true) 
     UIView.setAnimationDuration(movementDuration) 
     self.view.frame = CGRectOffset(self.view.frame, 0, movement) 
     UIView.commitAnimations() 
    } 
관련 문제