FDFullscreenPopGesture对源码几乎没有侵入,就实现了导航的显示和隐藏。他的实现思路是,给UIViewController和UINavigationController添加分类;
UINavigationController的实现
Method originalMethod = class_getInstanceMethod(self,@selector(pushViewController:animated:));
Method swizzledMethod =class_getInstanceMethod(self,@selector(fd_pushViewController:animated:));
method_exchangeImplementations(originalMethod, swizzledMethod);
通过runtime对系统的pushViewController进行了交换,然后在fd_pushViewController中给视图添加手势做侧滑操作,禁用系统的侧滑操作;
UIViewController的实现:
Method originalMethod =class_getInstanceMethod(self,@selector(viewWillAppear:));
Method swizzledMethod =class_getInstanceMethod(self,@selector(fd_viewWillAppear:));
method_exchangeImplementations(originalMethod, swizzledMethod);
通过runtime对系统的viewWillAppear进行了交换,然后在fd_viewWillAppear中对导航进行隐藏。
其他实现就是:
给控制器通过关联的方式添加属性,来设置导航的显示和隐藏;
弊端:
FDFullscreenPopGesture是一个自动全局设置的第三方,可能导致你以前是隐藏的导航栏,因为以前的代码因为没有重写fd_prefersNavigationBarHidden方法,导致导航显示出来。出现问题;
网友评论