How do you schedule a block to run on the next run loop iteration?

后端 未结 5 2350
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 04:36

I want to be able to execute a block on the next run loop iteration. It\'s not so important whether it gets executed at the beginning or the end of the next run

5条回答
  •  半阙折子戏
    2020-12-02 05:06

    Rob answer is great and informative. I'm not trying to replace it.

    Just reading the UIView documentation, I found :

    completion

    A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be NULL.

    So an easy solution would be:

    UIView.animate(withDuration: 0) {
        // anything
    }
    

提交回复
热议问题