QMUINavigationController+CNFloatManager.m
2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// 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