0
votes

I have UIView with animated frame size on long press gesture.

- (IBAction)longPressGesture:(id)sender {
    NSTimeInterval duration = 1;
    CGRect newFrame = self.view.frame;

    switch (((UIGestureRecognizer *)sender).state) {
        case UIGestureRecognizerStateBegan:
            newFrame.size.height += 100;
            break;
        case UIGestureRecognizerStateEnded:
            newFrame.size.height -= 100;
            break;            
        default:
            break;
    }

    [UIView animateWithDuration:duration animations:^{
        self.view.frame = newFrame;
    }];

}

On tap_begin frame height increase to maximum size (heigh + 100), on tap_end decrease to original size (heigh - 100). The problem is when I tap, frame start to grow and then while growing I release finger and second animation starts from large frame, not from current state.

For example frame start to animate from height 200 to 300 and in middle of animation (when frame height is 250) i release finger and frame height immediately sets to 300 and start to decrease to 200.

How can I implement behavior where I can interrupt first animation and start second from curent height (250 for example)?

Or behavior where first animation must complete at first and only after that start second animation?

1

1 Answers

3
votes

You could try using animateWithDuration:delay:options:animations:completion: and include the option setAnimationBeginsFromCurrentState.