#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
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
推薦閱讀更多精彩內(nèi)容
- 出處:http://www.akayzhang.com/article/6 背景 最近公司許多團隊進行升級php7...
- 最近在駕校學(xué)習(xí),采用的是一種叫做『智慧駕培』的教學(xué)模式——學(xué)員可以在網(wǎng)站(蘇州智慧駕培管理系統(tǒng))上預(yù)約教練,然后一...
- 微信公眾號的心智玩家群,經(jīng)過近兩個月的營運,心智新玩家們,一點點都開始玩出了感覺,我在我的簡書里已經(jīng)分享了不少TA...