diff --git a/GKNavigationBar.podspec b/GKNavigationBar.podspec index e928271..d8a4a56 100644 --- a/GKNavigationBar.podspec +++ b/GKNavigationBar.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'GKNavigationBar' - s.version = '1.6.6' + s.version = '1.7.0' s.license = 'MIT' s.summary = '自定义导航栏--导航栏联动' s.homepage = 'https://github.com/QuintGao/GKNavigationBar' diff --git a/GKNavigationBar/NavigationBar/GKNavigationBarConfigure.h b/GKNavigationBar/NavigationBar/GKNavigationBarConfigure.h index 82ff39a..f792e05 100644 --- a/GKNavigationBar/NavigationBar/GKNavigationBarConfigure.h +++ b/GKNavigationBar/NavigationBar/GKNavigationBarConfigure.h @@ -59,8 +59,12 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign) GKNavigationBarBackStyle backStyle; /// 是否禁止导航栏左右item间距调整,默认是NO +/// 1.7.0版本之后 只对带有GKCustomNavigationBar的控制器有效 @property (nonatomic, assign) BOOL gk_disableFixSpace; +/// 开启普通控制器的导航栏item间距调整,只能在对应的控制器中开启 +@property (nonatomic, assign) BOOL openSystemFixSpace; + /// 导航栏左侧按钮距屏幕左边间距,默认是0,可自行调整 @property (nonatomic, assign) CGFloat gk_navItemLeftSpace; @@ -73,9 +77,6 @@ NS_ASSUME_NONNULL_BEGIN /// 状态栏类型,默认UIStatusBarStyleDefault @property (nonatomic, assign) UIStatusBarStyle statusBarStyle; -// 调整导航栏间距时需要屏蔽的VC(默认nil),支持Class或NSString,NSString支持部分匹配如前缀 -@property (nonatomic, strong) NSArray *shiledItemSpaceVCs; - /// 导航栏左右间距,内部使用 @property (nonatomic, assign, readonly) BOOL disableFixSpace; @property (nonatomic, assign, readonly) CGFloat navItemLeftSpace; @@ -109,6 +110,9 @@ NS_ASSUME_NONNULL_BEGIN /// 获取bundle - (NSBundle *)gk_libraryBundle; +/// 是否禁止调整导航栏item间距 +- (BOOL)fixNavItemSpaceDisabled; + @end // from QMUI diff --git a/GKNavigationBar/NavigationBar/GKNavigationBarConfigure.m b/GKNavigationBar/NavigationBar/GKNavigationBarConfigure.m index a62b539..f3d1269 100644 --- a/GKNavigationBar/NavigationBar/GKNavigationBarConfigure.m +++ b/GKNavigationBar/NavigationBar/GKNavigationBarConfigure.m @@ -87,6 +87,11 @@ - (NSBundle *)gk_libraryBundle { return [NSBundle bundleWithURL:bundleURL]; } +- (BOOL)fixNavItemSpaceDisabled { +// NSLog(@"%d---%d", self.gk_disableFixSpace, self.openSystemFixSpace); + return self.gk_disableFixSpace && !self.openSystemFixSpace; +} + @end @interface GKPortraitViewController : UIViewController diff --git a/GKNavigationBar/NavigationBar/UINavigationController+GKNavigationBar.h b/GKNavigationBar/NavigationBar/UINavigationController+GKNavigationBar.h index 2a1ceea..389f36e 100644 --- a/GKNavigationBar/NavigationBar/UINavigationController+GKNavigationBar.h +++ b/GKNavigationBar/NavigationBar/UINavigationController+GKNavigationBar.h @@ -15,6 +15,9 @@ NS_ASSUME_NONNULL_BEGIN /// 开启系统导航与GKNavigationBar过渡处理,需要在显示系统导航栏的控制器中调用显示导航栏方法 @property (nonatomic, assign) BOOL gk_openSystemNavHandle; +/// 该导航栏是由内部隐藏的 +@property (nonatomic, assign) BOOL gk_hideNavigationBar; + @end NS_ASSUME_NONNULL_END diff --git a/GKNavigationBar/NavigationBar/UINavigationController+GKNavigationBar.m b/GKNavigationBar/NavigationBar/UINavigationController+GKNavigationBar.m index 4ee5c44..5e4a2e4 100644 --- a/GKNavigationBar/NavigationBar/UINavigationController+GKNavigationBar.m +++ b/GKNavigationBar/NavigationBar/UINavigationController+GKNavigationBar.m @@ -38,4 +38,13 @@ - (BOOL)gk_openSystemNavHandle { return [objc_getAssociatedObject(self, &kAssociatedObjectKey_openSystemNavHandle) boolValue]; } +static char kAssociatedObjectKey_hideNavigationBar; +- (void)setGk_hideNavigationBar:(BOOL)gk_hideNavigationBar { + objc_setAssociatedObject(self, &kAssociatedObjectKey_hideNavigationBar, @(gk_hideNavigationBar), OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + +- (BOOL)gk_hideNavigationBar { + return [objc_getAssociatedObject(self, &kAssociatedObjectKey_hideNavigationBar) boolValue]; +} + @end diff --git a/GKNavigationBar/NavigationBar/UINavigationItem+GKNavigationBar.m b/GKNavigationBar/NavigationBar/UINavigationItem+GKNavigationBar.m index 785389a..e13ba73 100644 --- a/GKNavigationBar/NavigationBar/UINavigationItem+GKNavigationBar.m +++ b/GKNavigationBar/NavigationBar/UINavigationItem+GKNavigationBar.m @@ -38,7 +38,7 @@ - (void)gk_setLeftBarButtonItem:(UIBarButtonItem *)leftBarButtonItem { } - (void)gk_setLeftBarButtonItem:(UIBarButtonItem *)leftBarButtonItem animated:(BOOL)animated { - if (!GKConfigure.gk_disableFixSpace && leftBarButtonItem) {//存在按钮且需要调节 + if (!GKConfigure.fixNavItemSpaceDisabled && leftBarButtonItem) {//存在按钮且需要调节 [self setLeftBarButtonItems:@[leftBarButtonItem] animated:animated]; } else {//不存在按钮,或者不需要调节 [self setLeftBarButtonItems:nil]; @@ -51,7 +51,7 @@ - (void)gk_setLeftBarButtonItems:(NSArray *)leftBarButtonItem } - (void)gk_setLeftBarButtonItems:(NSArray *)leftBarButtonItems animated:(BOOL)animated { - if (!GKConfigure.gk_disableFixSpace && leftBarButtonItems.count) {//存在按钮且需要调节 + if (!GKConfigure.fixNavItemSpaceDisabled && leftBarButtonItems.count) {//存在按钮且需要调节 UIBarButtonItem *firstItem = leftBarButtonItems.firstObject; CGFloat width = GKConfigure.gk_navItemLeftSpace - GKConfigure.gk_fixedSpace; if (firstItem.width == width) {//已经存在space @@ -71,7 +71,7 @@ - (void)gk_setRightBarButtonItem:(UIBarButtonItem *)rightBarButtonItem{ } - (void)gk_setRightBarButtonItem:(UIBarButtonItem *)rightBarButtonItem animated:(BOOL)animated { - if (!GKConfigure.gk_disableFixSpace && rightBarButtonItem) {//存在按钮且需要调节 + if (!GKConfigure.fixNavItemSpaceDisabled && rightBarButtonItem) {//存在按钮且需要调节 [self setRightBarButtonItems:@[rightBarButtonItem] animated:animated]; } else {//不存在按钮,或者不需要调节 [self setRightBarButtonItems:nil]; @@ -84,7 +84,7 @@ - (void)gk_setRightBarButtonItems:(NSArray *)rightBarButtonIt } - (void)gk_setRightBarButtonItems:(NSArray *)rightBarButtonItems animated:(BOOL)animated { - if (!GKConfigure.gk_disableFixSpace && rightBarButtonItems.count) {//存在按钮且需要调节 + if (!GKConfigure.fixNavItemSpaceDisabled && rightBarButtonItems.count) {//存在按钮且需要调节 UIBarButtonItem *firstItem = rightBarButtonItems.firstObject; CGFloat width = GKConfigure.gk_navItemRightSpace - GKConfigure.gk_fixedSpace; if (firstItem.width == width) {//已经存在space @@ -125,7 +125,7 @@ + (void)load { - (void)gk_layoutSubviews { [self gk_layoutSubviews]; - if (GKConfigure.gk_disableFixSpace) return; + if (GKConfigure.fixNavItemSpaceDisabled) return; if (![self isMemberOfClass:NSClassFromString(@"_UINavigationBarContentView")]) return; id layout = [self valueForKey:@"_layout"]; if (!layout) return; @@ -137,14 +137,14 @@ - (void)gk_layoutSubviews { - (void)gk__updateMarginConstraints { [self gk__updateMarginConstraints]; - if (GKConfigure.gk_disableFixSpace) return; + if (GKConfigure.fixNavItemSpaceDisabled) return; if (![self isMemberOfClass:NSClassFromString(@"_UINavigationBarContentViewLayout")]) return; [self gk_adjustLeadingBarConstraints]; [self gk_adjustTrailingBarConstraints]; } - (void)gk_adjustLeadingBarConstraints { - if (GKConfigure.gk_disableFixSpace) return; + if (GKConfigure.fixNavItemSpaceDisabled) return; NSArray *leadingBarConstraints = [self valueForKey:@"_leadingBarConstraints"]; if (!leadingBarConstraints) return; CGFloat constant = GKConfigure.gk_navItemLeftSpace - GKConfigure.gk_fixedSpace; @@ -156,7 +156,7 @@ - (void)gk_adjustLeadingBarConstraints { } - (void)gk_adjustTrailingBarConstraints { - if (GKConfigure.gk_disableFixSpace) return; + if (GKConfigure.fixNavItemSpaceDisabled) return; NSArray *trailingBarConstraints = [self valueForKey:@"_trailingBarConstraints"]; if (!trailingBarConstraints) return; CGFloat constant = GKConfigure.gk_fixedSpace - GKConfigure.gk_navItemRightSpace; diff --git a/GKNavigationBar/NavigationBar/UIViewController+GKNavigationBar.h b/GKNavigationBar/NavigationBar/UIViewController+GKNavigationBar.h index 653adee..92f2381 100644 --- a/GKNavigationBar/NavigationBar/UIViewController+GKNavigationBar.h +++ b/GKNavigationBar/NavigationBar/UIViewController+GKNavigationBar.h @@ -77,9 +77,13 @@ NS_ASSUME_NONNULL_BEGIN @property (nullable, nonatomic, strong) NSArray *gk_navRightBarButtonItems; /// 是否禁止调整当前控制器导航栏间距,默认GKConfigure.gk_disableFixSpace -/// 仅当GKConfigure.gk_disableFixSpace为NO时有效 +/// 对带有GKCustomNavigationBar的控制器有效 @property (nonatomic, assign) BOOL gk_disableFixNavItemSpace; +/// 是否开启当前控制器的导航栏item间距调整,默认NO +/// 对没有GKCustomNavigationBar的控制器有效 +@property (nonatomic, assign) BOOL gk_openFixNavItemSpace; + /// 导航栏左右按钮距离屏幕边缘的距离,需在设置左右item之前设置此属性 @property (nonatomic, assign) CGFloat gk_navItemLeftSpace; @property (nonatomic, assign) CGFloat gk_navItemRightSpace; diff --git a/GKNavigationBar/NavigationBar/UIViewController+GKNavigationBar.m b/GKNavigationBar/NavigationBar/UIViewController+GKNavigationBar.m index 9ef86a5..3ddbabc 100644 --- a/GKNavigationBar/NavigationBar/UIViewController+GKNavigationBar.m +++ b/GKNavigationBar/NavigationBar/UIViewController+GKNavigationBar.m @@ -44,14 +44,16 @@ + (void)load { } - (void)gk_viewDidLoad { - // bug fix #76,修改添加了子控制器后调整导航栏间距无效的bug - // 当创建了gk_navigationBar或者父控制器是导航控制器的时候才去调整导航栏间距 + // 设置默认状态 + self.gk_disableFixNavItemSpace = YES; + self.gk_openFixNavItemSpace = NO; + if ([self shouldHandleNavBar]) { // 设置默认导航栏间距 self.gk_navItemLeftSpace = GKNavigationBarItemSpace; self.gk_navItemRightSpace = GKNavigationBarItemSpace; - self.gk_disableFixNavItemSpace = [self checkFixNavItemSpace]; } + // 如果是根控制器,取消返回按钮 if (self.navigationController && self.navigationController.childViewControllers.count <= 1) { if (!self.gk_NavBarInit) return; @@ -69,6 +71,8 @@ - (void)gk_viewWillAppear:(BOOL)animated { if (!self.navigationController) return; if (self.gk_NavBarInit) { + self.gk_disableFixNavItemSpace = self.gk_disableFixNavItemSpace; + self.gk_openFixNavItemSpace = self.gk_openFixNavItemSpace; // 隐藏系统导航栏 if (!self.navigationController.gk_openSystemNavHandle) { [self hiddenSystemNavBar]; @@ -79,12 +83,16 @@ - (void)gk_viewWillAppear:(BOOL)animated { [self.view bringSubviewToFront:self.gk_navigationBar]; } }else { + if (self.navigationController && !self.navigationController.isNavigationBarHidden && ![self isNonFullScreen]) { + self.gk_disableFixNavItemSpace = self.gk_disableFixNavItemSpace; + self.gk_openFixNavItemSpace = self.gk_openFixNavItemSpace; + } [self restoreSystemNavBar]; } // bug fix #76,修改添加了子控制器后调整导航栏间距无效的bug // 当创建了gk_navigationBar或者父控制器是导航控制器的时候才去调整导航栏间距 - if ([self shouldHandleNavBar] && !self.gk_disableFixNavItemSpace) { + if (self.gk_openFixNavItemSpace) { // 每次控制器出现的时候重置导航栏间距 if (self.gk_navItemLeftSpace == GKNavigationBarItemSpace) { self.gk_navItemLeftSpace = GKConfigure.navItemLeftSpace; @@ -113,16 +121,6 @@ - (void)gk_viewDidAppear:(BOOL)animated { [self restoreSystemNavBar]; } - if (self.gk_disableFixNavItemSpace) { - [GKConfigure updateConfigure:^(GKNavigationBarConfigure * _Nonnull configure) { - configure.gk_disableFixSpace = YES; - }]; - }else { - [GKConfigure updateConfigure:^(GKNavigationBarConfigure * _Nonnull configure) { - configure.gk_disableFixSpace = configure.disableFixSpace; - }]; - } - [self gk_viewDidAppear:animated]; } @@ -201,6 +199,8 @@ - (GKCustomNavigationBar *)gk_navigationBar { objc_setAssociatedObject(self, &kAssociatedObjectKey_navigationBar, navigationBar, OBJC_ASSOCIATION_RETAIN_NONATOMIC); self.gk_NavBarInit = YES; + self.gk_disableFixNavItemSpace = GKConfigure.disableFixSpace; + self.gk_openFixNavItemSpace = YES; [self setupNavBarAppearance]; [self setupNavBarFrame]; } @@ -507,18 +507,30 @@ - (void)setGk_navRightBarButtonItems:(NSArray *)gk_navRightBa - (void)setGk_disableFixNavItemSpace:(BOOL)gk_disableFixNavItemSpace { objc_setAssociatedObject(self, &kAssociatedObjectKey_disableFixNavItemSpace, @(gk_disableFixNavItemSpace), OBJC_ASSOCIATION_RETAIN_NONATOMIC); - if (GKConfigure.gk_disableFixSpace) return; - if (gk_disableFixNavItemSpace != GKConfigure.gk_disableFixSpace) { - [GKConfigure updateConfigure:^(GKNavigationBarConfigure * _Nonnull configure) { - configure.gk_disableFixSpace = gk_disableFixNavItemSpace; - }]; - } + if (GKConfigure.gk_disableFixSpace == gk_disableFixNavItemSpace) return; + [GKConfigure updateConfigure:^(GKNavigationBarConfigure * _Nonnull configure) { + configure.gk_disableFixSpace = gk_disableFixNavItemSpace; + }]; } - (BOOL)gk_disableFixNavItemSpace { return [objc_getAssociatedObject(self, &kAssociatedObjectKey_disableFixNavItemSpace) boolValue]; } +static char kAssociatedObjectKey_openFixNavItemSpace; +- (void)setGk_openFixNavItemSpace:(BOOL)gk_openFixNavItemSpace { + objc_setAssociatedObject(self, &kAssociatedObjectKey_openFixNavItemSpace, @(gk_openFixNavItemSpace), OBJC_ASSOCIATION_RETAIN_NONATOMIC); + + if (GKConfigure.openSystemFixSpace == gk_openFixNavItemSpace) return; + [GKConfigure updateConfigure:^(GKNavigationBarConfigure * _Nonnull configure) { + configure.openSystemFixSpace = gk_openFixNavItemSpace; + }]; +} + +- (BOOL)gk_openFixNavItemSpace { + return [objc_getAssociatedObject(self, &kAssociatedObjectKey_openFixNavItemSpace) boolValue]; +} + static char kAssociatedObjectKey_navItemLeftSpace; - (void)setGk_navItemLeftSpace:(CGFloat)gk_navItemLeftSpace { objc_setAssociatedObject(self, &kAssociatedObjectKey_navItemLeftSpace, @(gk_navItemLeftSpace), OBJC_ASSOCIATION_RETAIN_NONATOMIC); @@ -695,24 +707,28 @@ - (void)setupNavBarAppearance { self.gk_navTitle = nil; } -- (void)setupNavBarFrame { +- (BOOL)isNonFullScreen { BOOL isNonFullScreen = NO; CGFloat viewW = GK_SCREEN_WIDTH; CGFloat viewH = GK_SCREEN_HEIGHT; - // 防止在init方法中创建导航栏会提前触发viewDidLoad方法,所以做下判断 if (self.isViewLoaded) { UIViewController *parentVC = self; - // 找到最上层的父类 + // 找到最上层的父控制器 while (parentVC.parentViewController) { parentVC = parentVC.parentViewController; } viewW = parentVC.view.frame.size.width; viewH = parentVC.view.frame.size.height; - if (viewW == 0 || viewH == 0) return; + if (viewW == 0 || viewH == 0) return NO; // 如果是通过present方式弹出且高度小于屏幕高度,则认为是非全屏 isNonFullScreen = self.presentingViewController && viewH < GK_SCREEN_HEIGHT; } + return isNonFullScreen; +} + +- (void)setupNavBarFrame { + BOOL isNonFullScreen = [self isNonFullScreen]; CGFloat navBarH = 0.0f; if (GK_IS_iPad) { // iPad @@ -736,41 +752,20 @@ - (void)setupNavBarFrame { } } } - self.gk_navigationBar.frame = CGRectMake(0, 0, viewW, navBarH); + self.gk_navigationBar.frame = CGRectMake(0, 0, GK_SCREEN_WIDTH, navBarH); [self.gk_navigationBar layoutSubviews]; } -- (BOOL)checkFixNavItemSpace { - // 判断是否需要屏蔽导航栏间距调整 - __block BOOL exist = NO; - [GKConfigure.shiledItemSpaceVCs enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { - if ([[obj class] isSubclassOfClass:[UIViewController class]]) { - if ([self isKindOfClass:[obj class]]) { - exist = YES; - *stop = YES; - } - }else if ([obj isKindOfClass:[NSString class]]) { - if ([NSStringFromClass(self.class) isEqualToString:obj]) { - exist = YES; - *stop = YES; - }else if ([NSStringFromClass(self.class) containsString:obj]) { - exist = YES; - *stop = YES; - } - } - }]; - return exist; -} - - (void)hiddenSystemNavBar { if (!self.navigationController.isNavigationBarHidden) { + self.navigationController.gk_hideNavigationBar = YES; [self.navigationController setNavigationBarHidden:YES]; } } - (void)restoreSystemNavBar { if (GKConfigure.gk_restoreSystemNavBar && [self shouldHandleNavBar]) { - if (self.navigationController.isNavigationBarHidden) { + if (self.navigationController.isNavigationBarHidden && self.navigationController.gk_hideNavigationBar) { [self.navigationController setNavigationBarHidden:NO]; } } diff --git a/GKNavigationBarExample/GKNavigationBarExample.xcodeproj/project.pbxproj b/GKNavigationBarExample/GKNavigationBarExample.xcodeproj/project.pbxproj index 65d9bd9..d96cc5d 100644 --- a/GKNavigationBarExample/GKNavigationBarExample.xcodeproj/project.pbxproj +++ b/GKNavigationBarExample/GKNavigationBarExample.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ 608FC6FF25469C9C003DB82F /* GKFloatTransition.m in Sources */ = {isa = PBXBuildFile; fileRef = 608FC6F625469C9C003DB82F /* GKFloatTransition.m */; }; 608FC70025469C9C003DB82F /* GKFloatView.m in Sources */ = {isa = PBXBuildFile; fileRef = 608FC6F725469C9C003DB82F /* GKFloatView.m */; }; 609E890D2644E3A300C15CB1 /* GKPresentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 609E890C2644E3A300C15CB1 /* GKPresentViewController.m */; }; + 60AF462C27C6061E00E6B76F /* GKDemo006ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 60AF462B27C6061E00E6B76F /* GKDemo006ViewController.m */; }; 60B3D7A8258AFBAF003A4C7C /* GKDemo005ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 60B3D7A7258AFBAF003A4C7C /* GKDemo005ViewController.m */; }; 60B70D77256F8A11008D62FC /* GKDemo004ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 60B70D76256F8A11008D62FC /* GKDemo004ViewController.m */; }; 794AFC32242F07EA00BECA1B /* GKBaseViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 794AFC31242F07E900BECA1B /* GKBaseViewController.m */; }; @@ -85,6 +86,8 @@ 608FC6F925469C9C003DB82F /* GKFloatView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GKFloatView.h; sourceTree = ""; }; 609E890B2644E3A300C15CB1 /* GKPresentViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GKPresentViewController.h; sourceTree = ""; }; 609E890C2644E3A300C15CB1 /* GKPresentViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GKPresentViewController.m; sourceTree = ""; }; + 60AF462A27C6061E00E6B76F /* GKDemo006ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GKDemo006ViewController.h; sourceTree = ""; }; + 60AF462B27C6061E00E6B76F /* GKDemo006ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GKDemo006ViewController.m; sourceTree = ""; }; 60B3D7A6258AFBAF003A4C7C /* GKDemo005ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GKDemo005ViewController.h; sourceTree = ""; }; 60B3D7A7258AFBAF003A4C7C /* GKDemo005ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GKDemo005ViewController.m; sourceTree = ""; }; 60B70D75256F8A11008D62FC /* GKDemo004ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GKDemo004ViewController.h; sourceTree = ""; }; @@ -435,6 +438,8 @@ 60B70D76256F8A11008D62FC /* GKDemo004ViewController.m */, 60B3D7A6258AFBAF003A4C7C /* GKDemo005ViewController.h */, 60B3D7A7258AFBAF003A4C7C /* GKDemo005ViewController.m */, + 60AF462A27C6061E00E6B76F /* GKDemo006ViewController.h */, + 60AF462B27C6061E00E6B76F /* GKDemo006ViewController.m */, 601BB2D3256CA96B001D59C8 /* GKDemoTransitionViewController.h */, 601BB2D4256CA96B001D59C8 /* GKDemoTransitionViewController.m */, 79C6AFEA237ED92900C636B9 /* GKDemoWebViewController.h */, @@ -633,6 +638,7 @@ 796CF8B8236D7BBF00983E9B /* GKToutiaoMineViewController.m in Sources */, 796CF8B7236D7BBF00983E9B /* GKToutiaoViewController.m in Sources */, 796CF8B1236D7BBF00983E9B /* UIView+Extension.m in Sources */, + 60AF462C27C6061E00E6B76F /* GKDemo006ViewController.m in Sources */, 796CF8B0236D7BBF00983E9B /* GKDemoBaseViewController.m in Sources */, 796CF8CA236D7BBF00983E9B /* GKWYNewsLiveViewController.m in Sources */, 796CF8C7236D7BBF00983E9B /* GKWYNewsCommentViewController.m in Sources */, diff --git a/GKNavigationBarExample/GKNavigationBarExample/AppDelegate.m b/GKNavigationBarExample/GKNavigationBarExample/AppDelegate.m index 04332a9..4e3547b 100644 --- a/GKNavigationBarExample/GKNavigationBarExample/AppDelegate.m +++ b/GKNavigationBarExample/GKNavigationBarExample/AppDelegate.m @@ -37,11 +37,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( // 导航栏返回按钮样式 configure.backStyle = GKNavigationBarBackStyleBlack; // 导航栏左右item间距 +// configure.gk_disableFixSpace = YES; configure.gk_navItemLeftSpace = 0.0f; configure.gk_navItemRightSpace = 10.0f; configure.gk_restoreSystemNavBar = YES; - - configure.shiledItemSpaceVCs = @[NSClassFromString(@"TZPhotoPickerController"), @"TZAlbumPickerController", @"TZ"]; }]; [GKGestureConfigure setupCustomConfigure:^(GKGestureHandleConfigure * _Nonnull configure) { diff --git a/GKNavigationBarExample/GKNavigationBarExample/Demo/DemoVC/GKDemo003ViewController.m b/GKNavigationBarExample/GKNavigationBarExample/Demo/DemoVC/GKDemo003ViewController.m index b4c0909..5118875 100644 --- a/GKNavigationBarExample/GKNavigationBarExample/Demo/DemoVC/GKDemo003ViewController.m +++ b/GKNavigationBarExample/GKNavigationBarExample/Demo/DemoVC/GKDemo003ViewController.m @@ -23,7 +23,7 @@ - (void)viewDidLoad { self.navigationItem.title = @"系统导航"; - self.gk_disableFixNavItemSpace = YES; +// self.gk_openFixNavItemSpace = YES; self.gk_navItemRightSpace = 40.0f; UIBarButtonItem *rightItem = [UIBarButtonItem gk_itemWithTitle:@"push" target:self action:@selector(click)]; rightItem.customView.backgroundColor = [UIColor blackColor]; diff --git a/GKNavigationBarExample/GKNavigationBarExample/Demo/DemoVC/GKDemo006ViewController.h b/GKNavigationBarExample/GKNavigationBarExample/Demo/DemoVC/GKDemo006ViewController.h new file mode 100644 index 0000000..94ce79e --- /dev/null +++ b/GKNavigationBarExample/GKNavigationBarExample/Demo/DemoVC/GKDemo006ViewController.h @@ -0,0 +1,17 @@ +// +// GKDemo006ViewController.h +// GKNavigationBarExample +// +// Created by gaokun on 2022/2/23. +// Copyright © 2022 QuintGao. All rights reserved. +// + +#import "GKBaseViewController.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface GKDemo006ViewController : GKBaseViewController + +@end + +NS_ASSUME_NONNULL_END diff --git a/GKNavigationBarExample/GKNavigationBarExample/Demo/DemoVC/GKDemo006ViewController.m b/GKNavigationBarExample/GKNavigationBarExample/Demo/DemoVC/GKDemo006ViewController.m new file mode 100644 index 0000000..61ae749 --- /dev/null +++ b/GKNavigationBarExample/GKNavigationBarExample/Demo/DemoVC/GKDemo006ViewController.m @@ -0,0 +1,143 @@ +// +// GKDemo006ViewController.m +// GKNavigationBarExample +// +// Created by gaokun on 2022/2/23. +// Copyright © 2022 QuintGao. All rights reserved. +// + +#import "GKDemo006ViewController.h" +#import "GKDemo003ViewController.h" + +@interface GKDemo006ViewController () + +@property (nonatomic, strong) UIButton *printBtn; + +@property (nonatomic, strong) UIButton *shareBtn; + +@end + +@implementation GKDemo006ViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.gk_navTitle = @"系统功能"; + self.view.backgroundColor = UIColor.whiteColor; + self.gk_navRightBarButtonItem = [UIBarButtonItem gk_itemWithTitle:@"哈哈" target:self action:@selector(systemAction:)]; + self.gk_navItemRightSpace = 40; + + [self.view addSubview:self.printBtn]; + [self.view addSubview:self.shareBtn]; + + [self.printBtn mas_makeConstraints:^(MASConstraintMaker *make) { + make.centerX.equalTo(self.view); + make.top.equalTo(self.gk_navigationBar.mas_bottom).offset(50); + make.width.mas_equalTo(100.0f); + make.height.mas_equalTo(40.0f); + }]; + + [self.shareBtn mas_makeConstraints:^(MASConstraintMaker *make) { + make.centerX.equalTo(self.view); + make.top.equalTo(self.printBtn.mas_bottom).offset(50); + make.width.mas_equalTo(100.0f); + make.height.mas_equalTo(40.0f); + }]; +} + +- (void)systemAction:(id)sender { + GKDemo003ViewController *demoVC = [[GKDemo003ViewController alloc] init]; + [self.navigationController pushViewController:demoVC animated:YES]; +} + +- (void)printAction:(id)sender{ + UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController]; + NSURL *url = [NSURL URLWithString:@"https://img2.baidu.com/it/u=566500983,3412942035&fm=253&fmt=auto&app=138&f=JPEG?w=440&h=955"]; + if (pic && [UIPrintInteractionController canPrintURL:url]) { + pic.delegate = self; + + // 打印任务细节在 UIPrintInfo 实例中设置。可以使用以下属性: + UIPrintInfo* printInfo = [UIPrintInfo printInfo]; + + // UIPrintInfoOutputType:给 UIKit 提供要打印内容的类型提示。可以是以下任意一个: + // .General(默认):文本和图形混合类型;允许双面打印。 + // .Grayscale:如果你的内容只包括黑色文本,那么该类型比 .General 更好。 + // .Photo:彩色或黑白图像;禁用双面打印,更适用于图像媒体的纸张类型。 + // .PhotoGrayscale:对于仅灰度的图像,根据打印机的不同,该类型可能比 .Photo 更好。 + printInfo.outputType = UIPrintInfoOutputGeneral; + // jobName String:此打印任务的名称。这个名字将被显示在设备的打印中心,对于有些打印机则显示在液晶屏上 + printInfo.jobName = @"PrintingImage"; + // UIPrintInfoDuplex:.None、.ShortEdge 或 .LongEd​​ge。short- 和 long- 的边界设置指示如何装订双面页面,而 .None 不支持双面打印(这里不是 UI 切换为双面打印,令人困惑) + printInfo.duplex = UIPrintInfoDuplexShortEdge; + + // UIPrintInfo:之前所述的打印任务的配置 + pic.printInfo = printInfo; + // showsPageRange Bool:当值为 true 时,让用户从打印源中选择一个子范围。这只在多页内容时有用,它默认关闭了图像。 + pic.showsPageRange = NO; + + pic.printingItem = url; + + void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) { + if (!completed && error) { + NSLog(@"FAILED! due to error in domain %@ with error code %lu", error.domain, error.code); + } + }; + + if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { + [pic presentFromRect:self.view.frame inView:self.view animated:YES completionHandler:completionHandler]; + } + else { + [pic presentAnimated:YES completionHandler:completionHandler]; + } + } +} + +- (void)shareAction:(id)sender { + // 分享文件 + NSURL *url = [NSURL URLWithString:@"https://img2.baidu.com/it/u=566500983,3412942035&fm=253&fmt=auto&app=138&f=JPEG?w=440&h=955"]; + + UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[url] applicationActivities:nil]; + +// 根据需要指定不需要分享的平台 + activityVC.excludedActivityTypes = @[UIActivityTypeMail,UIActivityTypePostToTwitter,UIActivityTypeMessage,UIActivityTypePrint,UIActivityTypeAssignToContact,UIActivityTypeAddToReadingList,UIActivityTypePostToFlickr,UIActivityTypePostToVimeo,UIActivityTypePostToTencentWeibo,UIActivityTypeOpenInIBooks]; + activityVC.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) { + if (completed) { // 确定分享 + NSLog(@"分享成功"); + }else { + NSLog(@"分享失败"); + } + }; + + UIPopoverPresentationController *popover = activityVC.popoverPresentationController; + if (popover) { + popover.sourceView = self.shareBtn; + popover.permittedArrowDirections = UIPopoverArrowDirectionDown; + } + + [self presentViewController:activityVC animated:YES completion:nil]; +} + +#pragma mark - UIPrintInteractionControllerDelegate + + +- (UIButton *)printBtn { + if (!_printBtn) { + _printBtn = [[UIButton alloc] init]; + [_printBtn setTitle:@"打印机" forState:UIControlStateNormal]; + [_printBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal]; + [_printBtn addTarget:self action:@selector(printAction:) forControlEvents:UIControlEventTouchUpInside]; + } + return _printBtn; +} + +- (UIButton *)shareBtn { + if (!_shareBtn) { + _shareBtn = [[UIButton alloc] init]; + [_shareBtn setTitle:@"系统分享" forState:UIControlStateNormal]; + [_shareBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal]; + [_shareBtn addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside]; + } + return _shareBtn; +} + +@end diff --git a/GKNavigationBarExample/GKNavigationBarExample/Demo/GKMainViewController.m b/GKNavigationBarExample/GKNavigationBarExample/Demo/GKMainViewController.m index b68d5bb..9320d3b 100644 --- a/GKNavigationBarExample/GKNavigationBarExample/Demo/GKMainViewController.m +++ b/GKNavigationBarExample/GKNavigationBarExample/Demo/GKMainViewController.m @@ -32,6 +32,7 @@ - (NSArray *)dataSource { @"系统导航", @"UITableViewController", @"WKWebView", + @"系统功能", @"抖音左右滑动", @"今日头条", @"网易云音乐", @@ -127,28 +128,28 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath if (vc) { [self.navigationController pushViewController:vc animated:YES]; }else { - if (indexPath.row == 6) { + if (indexPath.row == 7) { UINavigationController *nav = [UINavigationController rootVC:[GKDouyinHomeViewController new]]; nav.gk_openScrollLeftPush = YES; nav.modalPresentationStyle = UIModalPresentationFullScreen; [self presentViewController:nav animated:YES completion:nil]; - }else if (indexPath.row == 7) { + }else if (indexPath.row == 8) { GKToutiaoViewController *toutiaoVC = [GKToutiaoViewController new]; toutiaoVC.modalPresentationStyle = UIModalPresentationFullScreen; [self presentViewController:toutiaoVC animated:YES completion:nil]; - }else if (indexPath.row == 8) { + }else if (indexPath.row == 9) { GKWYMusicViewController *musicVC = [GKWYMusicViewController new]; musicVC.modalPresentationStyle = UIModalPresentationFullScreen; [self presentViewController:musicVC animated:YES completion:nil]; - }else if (indexPath.row == 9) { + }else if (indexPath.row == 10) { GKWYNewsViewController *newsVC = [GKWYNewsViewController new]; newsVC.modalPresentationStyle = UIModalPresentationFullScreen; [self presentViewController:newsVC animated:YES completion:nil]; - }else if (indexPath.row == 10) { + }else if (indexPath.row == 11) { GKWXViewController *wxVC = [GKWXViewController new]; wxVC.modalPresentationStyle = UIModalPresentationFullScreen; [self presentViewController:wxVC animated:YES completion:nil]; - }else if (indexPath.row == 11) { + }else if (indexPath.row == 12) { GKPresentViewController *presentVC = [GKPresentViewController new]; presentVC.gk_navTitle = @"presentVC"; diff --git a/README.md b/README.md index f68df02..594ef23 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,12 @@ Swift版本请看这里 → [GKNavigationBarSwift](https://github.com/QuintGao/G * 可实现push,pop时控制器缩放效果(如:今日头条) * 可实现左滑push一个控制器的效果(如:网易新闻) +## 1.7.0版本升级指南 +1.7.0版本重写了导航栏item间距调整的逻辑,1.7.0版本之后导航栏item间距调整只对使用GKCustomNavigationBar的控制器默认开启,其他控制器不会调整导航栏item间距,所以需要注意下面两点: +1、对于使用GKCustomNavigationBar的控制器,无需修改,如果想关闭导航栏间距调整设置gk_disableFixNavItemSpace即可 +2、对于使用系统导航栏的控制器,如果想要调整导航栏间距,需要在viewDidLoad中设置gk_openFixNavItemSpace为YES 全局配置是无效的。 +3、去掉了shiledItemSpaceVCs属性,可在单独控制器中处理。 + ## 使用 ### 1、在AppDelegate中添加导航配置