IOS全屏滑动返回
全程的用的思想是 Runtime 和 KVC 即 Runtime+KVC oc的关键性写法: oc 要加入头文件 #import<objc/runtime.h> 来获取运行循环需要打印的类。都是在父类都是NavigationViewController里面书写代码的
#import "CustomNavigationViewController.h"
#import<objc/runtime.h>
@interface CustomNavigationViewController ()<UIGestureRecognizerDelegate>
@end
@implementation CustomNavigationViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIGestureRecognizer *gesture = self.interactivePopGestureRecognizer;
UIView *gestureView = gesture.view;
gesture.enabled = NO;
unsigned int count = 0;
Ivar *var = class_copyIvarList([UIGestureRecognizer class], &count);
for(int i = 0;i<count;i++){
Ivar _var = *(var+i);
}
NSMutableArray *_targets = [gesture valueForKey:@"_targets"];
NSLog(@"%@",_targets);
NSLog(@"%@",_targets[0]);
id gestureRecognizerTarget = [_targets firstObject];
id navigationInteractiveTransition= [gestureRecognizerTarget valueForKey:@"target"];
SEL handleTransition = NSSelectorFromString(@"handleNavigationTransition:");
UIPanGestureRecognizer *popRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:navigationInteractiveTransition action:handleTransition];
[gestureView addGestureRecognizer:popRecognizer];
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
viewController.hidesBottomBarWhenPushed = YES;
[super pushViewController:viewController animated:animated];
}
@end
swift写法:
import UIKit
class CustomNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
guard let systemGes = interactivePopGestureRecognizer else { return }
guard let gesView = systemGes.view else { return }
let targets = systemGes.value(forKey: "_targets") as? [NSObject]
guard let targetObjc = targets?.first else { return }
debugPrint(targetObjc)
debugPrint(targets)
guard let target = targetObjc.value(forKey: "target") else { return }
let action = Selector(("handleNavigationTransition:"))
let panGes = UIPanGestureRecognizer()
gesView.addGestureRecognizer(panGes)
panGes.addTarget(target, action: action)
}
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
viewController.hidesBottomBarWhenPushed = true
super.pushViewController(viewController, animated: animated)
}
}
当然也有其他写法,或者借助框架等。 https://gitee.com/johnson__save_admin/iosslide-back-swift
https://gitee.com/johnson__save_admin/iosslide-back-oc
|