Completion block for popViewController

后端 未结 18 1607
离开以前
离开以前 2020-12-04 06:43

When dismissing a modal view controller using dismissViewController, there is the option to provide a completion block. Is there a similar equivalent for

18条回答
  •  渐次进展
    2020-12-04 07:25

    I know an answer has been accepted over two years ago, however this answer is incomplete.

    There is no way to do what you're wanting out-of-the-box

    This is technically correct because the UINavigationController API doesn't offer any options for this. However by using the CoreAnimation framework it's possible to add a completion block to the underlying animation:

    [CATransaction begin];
    [CATransaction setCompletionBlock:^{
        // handle completion here
    }];
    
    [self.navigationController popViewControllerAnimated:YES];
    
    [CATransaction commit];
    

    The completion block will be called as soon as the animation used by popViewControllerAnimated: ends. This functionality has been available since iOS 4.

提交回复
热议问题