QMUINavigationController+CNFloatManager.m 2.39 KB
//
//  QMUINavigationController+CNFloatManager.m
//  testIM
//
//  Created by 流诗语 on 2018/11/2.
//  Copyright © 2018年 cnlive. All rights reserved.
//

#import "QMUINavigationController+CNFloatManager.h"
#import <objc/runtime.h>
#import "HKFloatManager.h"
#import "HKTransitionPush.h"
#import "HKTransitionPop.h"
#import "CNLiveNavigationControllerDelegate.h"

@implementation QMUINavigationController (CNFloatManager)

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        ReplaceMethod([self class], @selector(viewDidLoad), @selector(CNLive_viewDidLoad));
    });
}

-(void)CNLive_viewDidLoad
{
    [self CNLive_viewDidLoad];
    self.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self;
    [self.interactivePopGestureRecognizer addTarget:self action:@selector(handleInteractivePopGestureRecognizer:)];
}
- (void)handleInteractivePopGestureRecognizer:(UIScreenEdgePanGestureRecognizer *)gestureRecognizer {
    UIGestureRecognizerState state = gestureRecognizer.state;
    if (state == UIGestureRecognizerStateBegan) {

    } else if (state == UIGestureRecognizerStateEnded) {
        if (CGRectGetMinX(self.topViewController.view.superview.frame) < 0) {
            [HKFloatManager shared].floatBall.alpha = 0;
            
        } else {
            [HKFloatManager shared].floatBall.alpha = 1;
            
        }
    }else{
        CGPoint point = [gestureRecognizer locationInView:self.view];
        [HKFloatManager shared].floatBall.alpha = point.x/(150);
    }
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    
    [[HKFloatManager shared] beginScreenEdgePanBack:gestureRecognizer];
    return YES;
}

CG_INLINE BOOL
ReplaceMethod(Class _class, SEL _originSelector, SEL _newSelector) {
    Method oriMethod = class_getInstanceMethod(_class, _originSelector);
    Method newMethod = class_getInstanceMethod(_class, _newSelector);
    if (!newMethod) {
        // class 里不存在该方法的实现
        return NO;
    }
    BOOL isAddedMethod = class_addMethod(_class, _originSelector, method_getImplementation(newMethod), method_getTypeEncoding(newMethod));
    if (isAddedMethod) {
        class_replaceMethod(_class, _newSelector, method_getImplementation(oriMethod), method_getTypeEncoding(oriMethod));
    } else {
        method_exchangeImplementations(oriMethod, newMethod);
    }
    return YES;
}
@end