Skip to content

Instantly share code, notes, and snippets.

@lexiaoyao20
Last active March 22, 2018 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lexiaoyao20/a46c5997fa9582ef2c60841e28d8b13b to your computer and use it in GitHub Desktop.
Save lexiaoyao20/a46c5997fa9582ef2c60841e28d8b13b to your computer and use it in GitHub Desktop.
在UIPageController中添加Pop返回手势
//
// NSObject+FMAdd.m
// Followme
//
// Created by Subo on 2018/3/22.
// Copyright © 2018年 com.followme. All rights reserved.
//
#import "NSObject+FMAdd.h"
@implementation NSObject (FMAdd)
+ (void)fm_swizzleSelector:(SEL)originalSelector withSelector:(SEL)swizzledSelector {
Class class = [self class];
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
BOOL success = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
if (success) {
class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
}else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
}
@end
#import "UIScrollView+FMAdd.h"
/**
UIPageViewController中全局的pop手势会失效,这里通过这种设置开启
*/
- (void)enablePopGesture {
for (UIView *view in self.pageViewController.view.subviews) {
if ([view isKindOfClass:[UIScrollView class]]) {
((UIScrollView *)view).popGestureEnable = YES;
break;
}
}
}
//
// UIScrollView+FMAdd.m
// Followme
//
// Created by Subo on 2018/3/22.
// Copyright © 2018年 com.followme. All rights reserved.
//
#import "UIScrollView+FMAdd.h"
#import "NSObject+FMAdd.h"
#import <objc/runtime.h>
@implementation UIScrollView (FMAdd)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[self fm_swizzleSelector:@selector(gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:)
withSelector:@selector(fm_gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:)];
});
}
- (BOOL)fm_gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
if (!self.popGestureEnable) {
return [self fm_gestureRecognizer:gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:otherGestureRecognizer];
}
if (self.contentOffset.x + self.contentInset.left <= 0) {
if ([otherGestureRecognizer.delegate isKindOfClass:NSClassFromString(@"_FDFullscreenPopGestureRecognizerDelegate")]) {
return YES;
}
}
return NO;
}
- (BOOL)popGestureEnable {
NSNumber *number = objc_getAssociatedObject(self, @selector(popGestureEnable));
return [number boolValue];
}
- (void)setPopGestureEnable:(BOOL)popGestureEnable {
objc_setAssociatedObject(self, @selector(popGestureEnable), @(popGestureEnable), OBJC_ASSOCIATION_COPY_NONATOMIC);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment