iOS monitor system sliding return event

This problem has been troubled for a long time, and there is no useful thing out of Baidu. Now I can’t drag it down because of laziness. So I went to the header file of UIViewController and looked at the methods one by one. When I saw the useful ones, I took them and tried them. Two methods were really found.

- (void)willMoveToParentViewController:(UIViewController)parent
- (void)didMoveToParentViewController:(UIViewController)parent

These two methods are methods in the category UIContainerViewControllerCallbacks written by the system.
You only need to rewrite these two methods in the currently used controller. Both methods will be called when the first push comes in, and the value of parent is not empty. When you start to use the system side sliding, willMove is called first, and the value of parent is empty; when the previous page is returned after the sliding, didMove is called, and the value of parent is also empty. If the sliding ends, the previous one is not returned. If the page is still on the current page after a slight stroke, the didMove method will not be called.
So if you want to do some operations on the previous page after sliding back, you can judge based on the value of parent in the didMove method.

- (void)willMoveToParentViewController:(UIViewController)parent{
[superwillMoveToParentViewController:parent];
NSLog(@"%s,%@",FUNCTION,parent);
}
- (void)didMoveToParentViewController:(UIViewController)parent{
[superdidMoveToParentViewController:parent];
NSLog(@"%s,%@",FUNCTION,parent);
if(!parent){
NSLog(@"页面pop成功了");
}
}

Transfer from: https://www.jianshu.com/p/b7331546a18b

Guess you like

Origin blog.csdn.net/qq_28285625/article/details/108979243