123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- //
- // UIViewController+SPSBInitialization.m
- // 我的社保
- //
- // Created by shanp on 2021/4/19.
- //
- #import "UIViewController+SPSBInitialization.h"
- #import <objc/runtime.h>
- #import "SPSBUIGeneralHeader.h"
- #import <JXHGeneralTools.h>
- #import <UMCommon/MobClick.h>
- @implementation UIViewController (SPSBInitialization)
- + (void)load {
- jxh_sizzleMethod(self, @selector(viewDidLoad), @selector(SPSBSwizzled_viewDidLoad));
- jxh_sizzleMethod(self, @selector(viewWillAppear:), @selector(SPSBSwizzled_viewWillAppear:));
- jxh_sizzleMethod(self, @selector(viewWillDisappear:), @selector(SPSBSwizzled_viewWillDisappear:));
- jxh_sizzleMethod(self, @selector(viewDidAppear:), @selector(SPSBSwizzled_viewDidAppear:));
- jxh_sizzleMethod(self, @selector(viewDidDisappear:), @selector(SPSBSwizzled_viewDidDisappear:));
- }
- - (void)SPSBSwizzled_viewDidLoad {
- if ([NSStringFromClass([self class]) hasPrefix:@"SPSB"]) {
- self.automaticallyAdjustsScrollViewInsets = false;
- self.view.backgroundColor = spsb_FFFFFF_color(1.f);
- if (!self.parentViewController || [self.parentViewController isKindOfClass:[UINavigationController class]]) {
- UIButton *backButton = self.spsb_backButton = [self createBackButton];
- backButton.frame = CGRectMake(0, 0, 50, jxh_navigationViewHeight());
- UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
-
- self.navigationItem.leftBarButtonItem = backItem;
- //启动返回手势
- self.navigationController.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self;
- }
-
- }
- [self SPSBSwizzled_viewDidLoad];
- }
- - (void)SPSBSwizzled_viewWillAppear:(BOOL)animated {
- if ([NSStringFromClass([self class]) hasPrefix:@"SPSB"]) {
- if (!self.parentViewController || [self.parentViewController isKindOfClass:[UINavigationController class]]) {
- if (![self isKindOfClass:[UINavigationController class]] && self.modalPresentationStyle != UIModalPresentationCustom) {
- [MobClick beginLogPageView:NSStringFromClass([self class])];
- if (self.navigationController) {
- [self.navigationController setNavigationBarHidden:self.spsb_isHiddenNavigationBar animated:true];
- }
- }
- }
- }
- [self SPSBSwizzled_viewWillAppear:animated];
- }
- - (void)SPSBSwizzled_viewWillDisappear:(BOOL)animated {
- if ([NSStringFromClass([self class]) hasPrefix:@"SPSB"]) {
- if (!self.parentViewController || [self.parentViewController isKindOfClass:[UINavigationController class]]) {
- if (![self isKindOfClass:[UINavigationController class]] && self.modalPresentationStyle != UIModalPresentationCustom) {
- [MobClick endLogPageView:NSStringFromClass([self class])];
- }
- }
- }
- [self SPSBSwizzled_viewWillDisappear:animated];
- }
- - (void)SPSBSwizzled_viewDidAppear:(BOOL)animated {
- if ([NSStringFromClass([self class]) hasPrefix:@"SPSB"]) {
- if (!self.parentViewController || [self.parentViewController isKindOfClass:[UINavigationController class]]) {
- if (self.navigationController && self.navigationController.viewControllers.count == 1) {
- //取消滑动手势返回
- self.navigationController.interactivePopGestureRecognizer.enabled = false;
- }
- }
-
- }
- [self SPSBSwizzled_viewDidAppear:animated];
- }
- - (void)SPSBSwizzled_viewDidDisappear:(BOOL)animated {
- if ([NSStringFromClass([self class]) hasPrefix:@"SPSB"]) {
- if (!self.parentViewController || [self.parentViewController isKindOfClass:[UINavigationController class]]) {
- //启动滑动手势返回
- self.navigationController.interactivePopGestureRecognizer.enabled = true;
- }
- }
- [self SPSBSwizzled_viewDidDisappear:animated];
- }
- - (void)cancelAction {
- jxh_endEdit();
- [self dismissViewControllerAnimated:true completion:^{
-
- }];
- }
- - (void)backAction {
- jxh_endEdit();
- [self.navigationController popViewControllerAnimated:true];
- }
- - (UIButton *)createBackButton {
- UIButton *backButton;
- if (!self.navigationController || self.navigationController.viewControllers.count == 1) {
- backButton = [UIButton convenienceWithFont:spsb_font(15) target:self action:@selector(cancelAction)];
- [backButton setTitle:@"取消" titleColor:self.spsb_isLightContent ? spsb_FFFFFF_color(1.f) : spsb_3296FB_color() state:JXHButtonControlStateNormal | JXHButtonControlStateHighlighted];
- } else {
- backButton = [UIButton convenienceWithFont:spsb_font(15) target:self action:@selector(backAction)];
- [backButton setTitle:@"返回" titleColor:self.spsb_isLightContent ? spsb_FFFFFF_color(1.f) : spsb_3296FB_color() image:self.spsb_isLightContent ? jxh_getImage(arrow_back_white) : jxh_getImage(arrow_back_blue) backgroundImage:nil state:JXHButtonControlStateNormal | JXHButtonControlStateHighlighted];
- [backButton setImageEdgeInsets:UIEdgeInsetsMake(0, -2, 0, 2)];
- }
- [backButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
- return backButton;
- }
- - (UIButton *)spsb_backButton {
- UIButton *object = objc_getAssociatedObject(self, @selector(setSpsb_backButton:));
- return object;
- }
- - (void)setSpsb_backButton:(UIButton *)spsb_backButton {
- objc_setAssociatedObject(self, _cmd, spsb_backButton, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- }
- - (UIStatusBarStyle)spsb_statusBarStyle {
- return [objc_getAssociatedObject(self, @selector(setSpsb_statusBarStyle:)) integerValue];
- }
- - (void)setSpsb_statusBarStyle:(UIStatusBarStyle)spsb_statusBarStyle {
- objc_setAssociatedObject(self, _cmd, @(spsb_statusBarStyle), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- }
- - (bool)spsb_isLightContent {
- return [objc_getAssociatedObject(self, @selector(setSpsb_isLightContent:)) boolValue];
- }
- - (void)setSpsb_isLightContent:(bool)spsb_isLightContent {
- if (spsb_isLightContent) {
- self.spsb_statusBarStyle = UIStatusBarStyleLightContent;
- } else {
- self.spsb_statusBarStyle = UIStatusBarStyleDefault;
- }
- [self setNeedsStatusBarAppearanceUpdate];
- objc_setAssociatedObject(self, _cmd, @(spsb_isLightContent), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- }
- - (bool)spsb_isHiddenNavigationBar {
- return [objc_getAssociatedObject(self, @selector(setSpsb_isHiddenNavigationBar:)) boolValue];
- }
- - (void)setSpsb_isHiddenNavigationBar:(bool)spsb_isHiddenNavigationBar {
- objc_setAssociatedObject(self, _cmd, @(spsb_isHiddenNavigationBar), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- }
- @end
|