UINavigationController+PushOneVC.m
1.17 KB
//
// UINavigationController+PushOneVC.m
// CNLiveScioLive
//
// Created by CNLive on 2021/8/27.
// Copyright © 2021 CNLive. All rights reserved.
//
#import "UINavigationController+PushOneVC.h"
#import <objc/runtime.h>
@implementation UINavigationController (PushOneVC)
+(void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Method origin = class_getInstanceMethod(self, @selector(pushViewController:animated:));
Method new = class_getInstanceMethod(self, @selector(CN_pushViewController:animated:));
method_exchangeImplementations(origin, new);
});
}
-(void)CN_pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if ([self.viewControllers.lastObject isKindOfClass:[viewController class]]) {
NSMutableArray *controllersAry = [NSMutableArray arrayWithArray:self.viewControllers];
[controllersAry replaceObjectAtIndex:self.viewControllers.count-1 withObject:viewController];
[self setViewControllers:controllersAry animated:YES];
}else{
self.modalPresentationStyle = UIModalPresentationFullScreen;
[self CN_pushViewController:viewController animated:YES];
}
}
@end