Commit 736ce274 authored by 汪洋's avatar 汪洋

删除WMNavigationController.m中无用的代码

parent 3ad76ba0
......@@ -8,10 +8,5 @@
#import <UIKit/UIKit.h>
/**
* @author wangyang
*
* 内部所有代码都是在处理自定义后退按键时,滑动后退(即interactivePopGestureRecognizer)不好使的问题
*/
@interface WMNavigationController : UINavigationController
@end
\ No newline at end of file
@end
......@@ -7,127 +7,13 @@
//
#import "WMNavigationController.h"
#import <objc/runtime.h>
@interface WMNavigationController () <UINavigationControllerDelegate, UIGestureRecognizerDelegate>
/// A Boolean value indicating whether navigation controller is currently pushing a new view controller on the stack.
@property (nonatomic, getter = isDuringPushAnimation) BOOL duringPushAnimation;
/// A real delegate of the class. `delegate` property is used only for keeping an internal state during
/// animations – we need to know when the animation ended, and that info is available only
/// from `navigationController:didShowViewController:animated:`.
@property (weak, nonatomic) id<UINavigationControllerDelegate> realDelegate;
@end
@implementation WMNavigationController
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationBarHidden = YES;
// 处理使用leftBarButton作为返回时,interactivePopGestureRecognizer不好使的问题
if (!self.delegate) {
self.delegate = self;
}
self.interactivePopGestureRecognizer.delegate = self;
// 这样在push时,view不会在导航栏上显示一黑色。尤其是在导航栏为透明时能看到
self.view.backgroundColor = [UIColor whiteColor];
}
- (void)dealloc
{
self.delegate = nil;
self.interactivePopGestureRecognizer.delegate = nil;
}
- (void)setDelegate:(id<UINavigationControllerDelegate>)delegate
{
[super setDelegate:delegate ? self : nil];
self.realDelegate = delegate != self ? delegate : nil;
}
- (void)pushViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
if (self.duringPushAnimation) {
return;
}
if (animated) {
self.duringPushAnimation = YES;
}
[super pushViewController:viewController animated:animated];
}
#pragma mark UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController
didShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
NSCAssert(self.interactivePopGestureRecognizer.delegate == self, @"WMNavigationController won't work correctly if you change interactivePopGestureRecognizer's delegate.");
self.duringPushAnimation = NO;
if ([self.realDelegate respondsToSelector:_cmd]) {
[self.realDelegate navigationController:navigationController didShowViewController:viewController animated:animated];
}
}
- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController*)fromVC toViewController:(UIViewController*)toVC
{
if ([self.realDelegate respondsToSelector:_cmd]) {
return [self.realDelegate navigationController:navigationController animationControllerForOperation:operation fromViewController:fromVC toViewController:toVC];
}
return nil;
}
- (id <UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController*)navigationController interactionControllerForAnimationController:(id <UIViewControllerAnimatedTransitioning>)animationController
{
if ([self.realDelegate respondsToSelector:_cmd]) {
return [self.realDelegate navigationController:navigationController interactionControllerForAnimationController:animationController];
}
return nil;
}
#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer == self.interactivePopGestureRecognizer) {
// Disable pop gesture in two situations:
// 1) when the pop animation is in progress
// 2) when user swipes quickly a couple of times and animations don't have time to be performed
return [self.viewControllers count] > 1 && !self.isDuringPushAnimation;
} else {
// default value
return YES;
}
}
#pragma mark - Method Forward
// Thanks for the idea goes to: https://github.com/steipete/PSPDFTextView/blob/ee9ce04ad04217efe0bc84d67f3895a34252d37c/PSPDFTextView/PSPDFTextView.m#L148-164
- (BOOL)respondsToSelector:(SEL)s
{
return [super respondsToSelector:s] || [self.realDelegate respondsToSelector:s];
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)s
{
return [super methodSignatureForSelector:s] ?: [(id)self.realDelegate methodSignatureForSelector:s];
}
- (void)forwardInvocation:(NSInvocation *)invocation
{
id delegate = self.realDelegate;
if ([delegate respondsToSelector:invocation.selector]) {
[invocation invokeWithTarget:delegate];
}
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment