iOS Animation not set to endpoint when used inside a UITextField in didBegin

1

I want when the user enters a UITextField field, make a simple animation of moving a UIView down, for example.

If I put my Up Inside routine it works, the same routine in didBegin of UItextfield does not work, it animates down and when it arrives at the set point it returns to the place of departure.

PS: I 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);
}
    
asked by anonymous 04.10.2014 / 23:06

1 answer

1

Good afternoon Moacir, I already used animations in the same situation as yours. I have decided as follows:

-(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];
        }
    }
    
06.10.2014 / 18:47