NSLayoutConstraint.constant ignoring animation

前端 未结 4 720
情歌与酒
情歌与酒 2021-01-31 11:09

I\'m creating an autolayout-friendly split view class for one of my applications. Among its various features is that it can collapse panes, and can animate their collapse, much

4条回答
  •  梦谈多话
    2021-01-31 11:59

    You have to first set the completion handler and only then send the message to the animator proxy. Otherwise, it seems that setting the completion handler after the animation started fires it immediately and the constant is removed before the animation has time to finish. I have just checked this with a piece of simple code:

    [NSAnimationContext beginGrouping];
    NSAnimationContext.currentContext.duration = animagionDuration;
    NSAnimationContext.currentContext.completionHandler = ^{
      [self removeConstraint:collapseConstraint];
    };
    [collapseConstraint.animator setConstant:expandedHeight];
    

    [NSAnimationContext endGrouping]; This works perfectly, but if you set completion handler after -setConstant:, the animation does not have a chance to run.

提交回复
热议问题