|
// |
|
// UINavigationController+Swizzle.m |
|
// |
|
// Created by Zsombor Szabó on 11/19/10. |
|
// Copyright 2010 IZE. All rights reserved. |
|
// |
|
|
|
#import "UINavigationController+Swizzle.h" |
|
|
|
#import <objc/runtime.h> |
|
#import <objc/message.h> |
|
|
|
void SwizzleClassSelectors(Class c, SEL orig, SEL new) |
|
{ |
|
Method origMethod = class_getInstanceMethod(c, orig); |
|
Method newMethod = class_getInstanceMethod(c, new); |
|
if(class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) |
|
class_replaceMethod(c, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod)); |
|
else |
|
method_exchangeImplementations(origMethod, newMethod); |
|
} |
|
|
|
@implementation UINavigationController (Swizzle) |
|
|
|
- (void)_doNothingForSetNavigationBarHidden:(BOOL)hidden |
|
{ |
|
NSLog(@"%s", __FUNCTION__); |
|
} |
|
|
|
- (void)_doNothingForSetNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated |
|
{ |
|
NSLog(@"%s", __FUNCTION__); |
|
} |
|
|
|
+ (void)_setNavbarMethodsEnabled:(BOOL)enabled |
|
{ |
|
static BOOL swizzled = NO; |
|
|
|
if (enabled == NO) |
|
{ |
|
if (swizzled == NO) |
|
{ |
|
swizzled = YES; |
|
|
|
SwizzleClassSelectors([UINavigationController class], @selector(setNavigationBarHidden:), @selector(_doNothingForSetNavigationBarHidden:)); |
|
SwizzleClassSelectors([UINavigationController class], @selector(setNavigationBarHidden:animated:), @selector(_doNothingForSetNavigationBarHidden:animated:)); |
|
} |
|
} |
|
|
|
else |
|
{ |
|
if (swizzled == YES) |
|
{ |
|
swizzled = NO; |
|
|
|
SwizzleClassSelectors([UINavigationController class], @selector(_doNothingForSetNavigationBarHidden:), @selector(setDrawingEnabled:)); |
|
SwizzleClassSelectors([UINavigationController class], @selector(_doNothingForSetNavigationBarHidden:animated:), @selector(setNavigationBarHidden:animated:)); |
|
} |
|
} |
|
} |