#import <UIKit/UIKit.h>
@interface UIViewController (NavigationBar)
@property (nonatomic, assign) IBInspectable BOOL hidesNavigationBarWhenPush;
@end
#import "UIViewController+NavigationBar.h"
#import <objc/runtime.h>
@implementation UIViewController (NavigationBar)
const void *kHidesNavigationBarWhenPush = "kHidesNavigationBarWhenPush";
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
SEL originalSelector = @selector(viewWillAppear:);
SEL swizzledSelector = @selector(_viewWillAppear:);
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class , swizzledSelector);
BOOL didAddMethod = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
if (didAddMethod) {
class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
});
}
- (void)_viewWillAppear:(BOOL)animated {
[self _viewWillAppear:animated];
// self.hidesBottomBarWhenPushed = false;
[self.navigationController setNavigationBarHidden:self.hidesNavigationBarWhenPush animated:animated];
}
- (BOOL)hidesNavigationBarWhenPush {
return objc_getAssociatedObject(self, kHidesNavigationBarWhenPush);
}
- (void)setHidesNavigationBarWhenPush:(BOOL)hidesNavigationBarWhenPush {
objc_setAssociatedObject(self, kHidesNavigationBarWhenPush, [NSNumber numberWithBool:hidesNavigationBarWhenPush], OBJC_ASSOCIATION_ASSIGN);
}
@end
UIViewController扩展hidesNavagationBarWhenPush
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 出处:http://www.akayzhang.com/article/6 背景 最近公司许多团队进行升级php7...
- 微信公众号的心智玩家群,经过近两个月的营运,心智新玩家们,一点点都开始玩出了感觉,我在我的简书里已经分享了不少TA...