美文网首页
runtime实现全屏pop手势

runtime实现全屏pop手势

作者: 那就这样吧_ | 来源:发表于2017-06-03 15:09 被阅读0次
  • 自定义 NavigationController 继承于系统 UINavigationController

  • 导入头文件 #import <objc/runtime.h>

  • NavigationController 中实现如下方法

    // OBJC
    - (void)viewDidLoad {
        [super viewDidLoad];
         
         // 取出系统pop手势的`target`和`action`
         NSArray *targetObjs = [self.interactivePopGestureRecognizer valueForKey:@"_targets"];
         id target = [targetObjs.firstObject valueForKey:@"target"];
         SEL sel = NSSelectorFromString(@"handleNavigationTransition:");
          
         UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:target action:sel];
         [self.view addGestureRecognizer:panGesture];
      
    }
    
    // swift
    override func viewDidLoad() {
        super.viewDidLoad()
      
        // 获取系统pop手势的target和action
        guard let targets = interactivePopGestureRecognizer?.value(forKey: "_targets") as? [NSObject] else { return }
        let targetObj = targets.first
        let target = targetObj?.value(forKey: "target")
        let action = Selector(("handleNavigationTransition:"))
      
        let panGesture = UIPanGestureRecognizer(target: target, action: action)
        view.addGestureRecognizer(panGesture)
      
    }
    
  • runtime的使用

    - OBJC
          unsigned int outCount = 0;
          Ivar *ivars = class_copyIvarList([UIGestureRecognizer class], &outCount);
          
          unsigned int outCountMethod = 0;
          Method *methods = class_copyMethodList([UIGestureRecognizer class], &outCountMethod);
          
          for (unsigned int i = 0; i < outCount; i++) {
              Ivar ivar = ivars[i];
              NSString *key = [NSString stringWithUTF8String:ivar_getName(ivar)];
              NSLog(@"%@", key);
          }
    
          NSLog(@"==========");
    
          for (unsigned int i = 0; i < outCountMethod; i++) {
              Method method = methods[i];
              SEL sel = method_getName(method);
              NSString *selName = NSStringFromSelector(sel);
              NSLog(@"%@", selName);
          }
    
    - swift
          // 获取 UIGestureRecognizer 的属性列表
          var count: UInt32 = 0
          let ivars = class_copyIvarList(UIGestureRecognizer.self, &count)!
          for i in 0..<count {
              let nameP = ivar_getName(ivars[Int(i)])!
              let name = String(cString: nameP)
              print(name)
          }
    

相关文章

  • runtime实现全屏pop手势

    自定义 NavigationController 继承于系统 UINavigationController 导入头...

  • iOS 全屏返回

    iOS 全屏返回 BBGestureBack iOS 全屏手势返回 滑动返回 pop 动画效果 这种手势主流App...

  • iOS 全屏手势返回

    BBGestureBack BBGestureBack iOS 全屏手势返回 滑动返回 pop 动画效果 这种手势...

  • iOS 右滑返回

    BBGestureBack BBGestureBack iOS 全屏手势返回 滑动返回 pop 动画效果 这种手势...

  • BBGestureBack 手势返回

    BBGestureBack BBGestureBack iOS 全屏手势返回 滑动返回 pop 动画效果 这种手势...

  • iOS实现全屏pop手势

    实现全局的pop手势 需要先获取系统手势交互对应interactivePopGestureRecognizer,获...

  • 利用runtime获取系统自带的pop手势,实现全屏pop

    实现思路 iOS 7.0系统增加了滑动的pop手势,可惜的是响应范围太小,只是屏幕的边缘位置.我们可以利用runt...

  • iOS 手势返回

    iOS 手势返回 BBGestureBack iOS 全屏手势返回 滑动返回 pop 动画效果 这种手势主流App...

  • iOS 右滑返回

    iOS 右滑返回 BBGestureBack iOS 全屏手势返回 滑动返回 pop 动画效果 这种手势主流App...

  • iOS 侧滑返回

    iOS 侧滑返回 BBGestureBack iOS 全屏手势返回 滑动返回 pop 动画效果 这种手势主流App...

网友评论

      本文标题:runtime实现全屏pop手势

      本文链接:https://www.haomeiwen.com/subject/acfmfxtx.html