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

前端 未结 4 1313
刺人心
刺人心 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:52

    As per the documentation of View class reference: If you used any of the class methods such as animateWithDuration:delay:options:animations:completion: if the duration is set to negative value or 0, the changes are made without performing animation. so I did something like this to stop the infinite animation:

    [UIView animateWithDuration:0.0 animations:^{
          button.layer.affineTransform = CGAffineTransformIdentity;
      }];
    

    I think this is better than removing all animations from the layer as in the suggested answer. Note that this is applicable for all other class animation methods in the UIView class.

提交回复
热议问题