Stop an auto-reverse / infinite-repeat UIView animation with a BOOL / completion block

前端 未结 4 1310
刺人心
刺人心 2021-01-01 11:06

I\'m setting up the following UIView animateWithDuration: method, with the intention of setting my animationOn BOOL elsewhere in the program to can

4条回答
  •  长发绾君心
    2021-01-01 11:45

    Old but another option.

    You can also setup another animation which is not repeating on the same view, that way you can also capture it in the current state and return it to how it is by using the option UIViewAnimationOptionBeginFromCurrentState. Your completion block is also called.

    -(void)someEventSoStop
    {
        button.transform = CGAffineTransformMakeScale(1.0, 1.0);
        [UIView animateWithDuration: 0.4
                              delay: 0.0
                            options: UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState
                         animations: ^{
                             button.transform = CGAffineTransformIdentity;
                         } completion: ^(BOOL finished){
    
                         }];
    }
    

提交回复
热议问题