iOS Animation does not fix the endpoint when used inside a Uitextfield in the didBegin

Asked

Viewed 39 times

1

I want when the user enters a field UITextField, make an animation simple to move a UIView down, for example.

If I put my Up Inside routine works, the same routine in didBegin of UItextfield doesn’t work, it animates down and when it reaches the set point it goes back to the starting place.

PS: use the same routine in both cases.

Does anyone have any idea what might be wrong?

Routine:

-(IBAction)testa:(id)sender {
    CGPoint fromPt = self.viewStatus.layer.position;
    CGPoint toPt = CGPointMake(fromPt.x, fromPt.y+200);

    CABasicAnimation* anime = [CABasicAnimation animationWithKeyPath:@"position"];
    anime.delegate = self;
    anime.removedOnCompletion = NO;
    anime.duration = 2;
    anime.fromValue = [NSValue valueWithCGPoint:fromPt];
    anime.toValue = [NSValue valueWithCGPoint:toPt];
    CAMediaTimingFunction* tf = [CAMediaTimingFunction
                                 functionWithName:kCAMediaTimingFunctionEaseOut];
    anime.timingFunction = tf;
    [self.viewStatus.layer addAnimation:anime forKey:@"ResizeForKeyboard"];

    self.viewStatus.frame = CGRectMake(self.viewStatus.frame.origin.x,
                                       toPt.y,
                                       self.viewStatus.frame.size.width,
                                       self.viewStatus.frame.size.height);
}
  • shared a folder with the project I made to test. Just unzip the zip. https://www.dropbox.com/s/mj4ceg6v2uo7vaz/teste.zip?dl=0

1 answer

1

Good afternoon Moacir, I have used animations in the same situation as yours. I solved it in the following way:

-(void)textFieldDidBeginEditing:(UITextField *)textField{
            [UIView animateWithDuration:2.0 delay:0
                                options:UIViewAnimationCurveEaseOut
                             animations:^{
                                 [viewStatus setFrame: CGRectMake(fromPt.x, fromPt.y+200, viewComponents.frame.size.width, viewComponents.frame.size.height)];
                             }completion:nil];
        }
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.