From 2575569bd02841fcd9da7ddcbfa8227d08748c2b Mon Sep 17 00:00:00 2001 From: QuintGao <1094887059@qq.com> Date: Fri, 7 May 2021 14:22:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=BE=E7=BD=AE=E8=83=8C?= =?UTF-8?q?=E6=99=AF=E8=89=B2=E6=97=A0=E6=95=88=E9=97=AE=E9=A2=98#71=20#73?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=AF=B9=E9=9D=9E=E5=85=A8=E5=B1=8F?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GKNavigationBar.podspec | 2 +- .../NavigationBar/GKCustomNavigationBar.h | 3 + .../NavigationBar/GKCustomNavigationBar.m | 2 +- .../NavigationBar/GKNavigationBarConfigure.h | 84 ++++++++++--------- .../NavigationBar/GKNavigationBarConfigure.m | 66 +++++++++++++++ .../NavigationBar/GKNavigationBarDefine.h | 4 +- .../NavigationBar/UIImage+GKNavigationBar.m | 6 +- .../UIViewController+GKNavigationBar.m | 35 ++++++-- .../project.pbxproj | 6 ++ .../Demo/BaseVC/GKBaseNavigationController.m | 14 ++-- .../Demo/BaseVC/GKBaseViewController.m | 8 ++ .../Demo/BaseVC/GKPresentViewController.h | 17 ++++ .../Demo/BaseVC/GKPresentViewController.m | 38 +++++++++ .../Demo/GKMainViewController.m | 11 ++- README.md | 3 +- 15 files changed, 238 insertions(+), 61 deletions(-) create mode 100644 GKNavigationBarExample/GKNavigationBarExample/Demo/BaseVC/GKPresentViewController.h create mode 100644 GKNavigationBarExample/GKNavigationBarExample/Demo/BaseVC/GKPresentViewController.m diff --git a/GKNavigationBar.podspec b/GKNavigationBar.podspec index 01a7da1..e47c0db 100644 --- a/GKNavigationBar.podspec +++ b/GKNavigationBar.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'GKNavigationBar' - s.version = '1.5.2' + s.version = '1.5.3' s.license = 'MIT' s.summary = '自定义导航栏--导航栏联动' s.homepage = 'https://github.com/QuintGao/GKNavigationBar' diff --git a/GKNavigationBar/NavigationBar/GKCustomNavigationBar.h b/GKNavigationBar/NavigationBar/GKCustomNavigationBar.h index 0c0d857..baed709 100644 --- a/GKNavigationBar/NavigationBar/GKCustomNavigationBar.h +++ b/GKNavigationBar/NavigationBar/GKCustomNavigationBar.h @@ -18,6 +18,9 @@ NS_ASSUME_NONNULL_BEGIN // 导航栏分割线是否隐藏 @property (nonatomic, assign) BOOL gk_navLineHidden; +// 在非全屏模式下显示 +@property (nonatomic, assign) BOOL gk_nonFullScreen; + @end NS_ASSUME_NONNULL_END diff --git a/GKNavigationBar/NavigationBar/GKCustomNavigationBar.m b/GKNavigationBar/NavigationBar/GKCustomNavigationBar.m index e932570..390be7d 100644 --- a/GKNavigationBar/NavigationBar/GKCustomNavigationBar.m +++ b/GKNavigationBar/NavigationBar/GKCustomNavigationBar.m @@ -30,7 +30,7 @@ - (void)layoutSubviews { obj.frame = frame; }else { CGRect frame = obj.frame; - frame.origin.y = self.frame.size.height - GK_NAVBAR_HEIGHT; + frame.origin.y = self.frame.size.height - (self.gk_nonFullScreen ? GK_NAVBAR_HEIGHT_NFS : GK_NAVBAR_HEIGHT); obj.frame = frame; } }]; diff --git a/GKNavigationBar/NavigationBar/GKNavigationBarConfigure.h b/GKNavigationBar/NavigationBar/GKNavigationBarConfigure.h index c25e4f3..8c95583 100644 --- a/GKNavigationBar/NavigationBar/GKNavigationBarConfigure.h +++ b/GKNavigationBar/NavigationBar/GKNavigationBarConfigure.h @@ -87,6 +87,9 @@ NS_ASSUME_NONNULL_BEGIN /// 获取当前item修复间距 - (CGFloat)gk_fixedSpace; +/// 获取bundle +- (NSBundle *)gk_libraryBundle; + @end // from QMUI @@ -105,62 +108,67 @@ NS_ASSUME_NONNULL_BEGIN @property (class, nonatomic, readonly) BOOL isRegularScreen; /// iPhone 12 Pro Max -@property(class, nonatomic, readonly) BOOL is67InchScreen; +@property (class, nonatomic, readonly) BOOL is67InchScreen; /// iPhone XS Max / 11 Pro Max -@property(class, nonatomic, readonly) BOOL is65InchScreen; +@property (class, nonatomic, readonly) BOOL is65InchScreen; /// iPhone 12 / 12 Pro -@property(class, nonatomic, readonly) BOOL is61InchScreenAndiPhone12; +@property (class, nonatomic, readonly) BOOL is61InchScreenAndiPhone12; /// iPhone XR / 11 -@property(class, nonatomic, readonly) BOOL is61InchScreen; +@property (class, nonatomic, readonly) BOOL is61InchScreen; /// iPhone X / XS / 11Pro -@property(class, nonatomic, readonly) BOOL is58InchScreen; +@property (class, nonatomic, readonly) BOOL is58InchScreen; /// iPhone 6,6s,7,8 Plus -@property(class, nonatomic, readonly) BOOL is55InchScreen; +@property (class, nonatomic, readonly) BOOL is55InchScreen; /// iPhone 12 mini -@property(class, nonatomic, readonly) BOOL is54InchScreen; +@property (class, nonatomic, readonly) BOOL is54InchScreen; /// iPhone 6,6s,7,8,SE2 -@property(class, nonatomic, readonly) BOOL is47InchScreen; +@property (class, nonatomic, readonly) BOOL is47InchScreen; /// iPhone 5,5s,5c,SE -@property(class, nonatomic, readonly) BOOL is40InchScreen; +@property (class, nonatomic, readonly) BOOL is40InchScreen; /// iPhone 4 -@property(class, nonatomic, readonly) BOOL is35InchScreen; - -@property(class, nonatomic, readonly) CGSize screenSizeFor67Inch; -@property(class, nonatomic, readonly) CGSize screenSizeFor65Inch; -@property(class, nonatomic, readonly) CGSize screenSizeFor61InchAndiPhone12; -@property(class, nonatomic, readonly) CGSize screenSizeFor61Inch; -@property(class, nonatomic, readonly) CGSize screenSizeFor58Inch; -@property(class, nonatomic, readonly) CGSize screenSizeFor55Inch; -@property(class, nonatomic, readonly) CGSize screenSizeFor54Inch; -@property(class, nonatomic, readonly) CGSize screenSizeFor47Inch; -@property(class, nonatomic, readonly) CGSize screenSizeFor40Inch; -@property(class, nonatomic, readonly) CGSize screenSizeFor35Inch; - -// 导航栏高度,包括竖屏,横屏,放大模式 -// 机型\高度 尺寸 竖屏 横屏 放大模式 -// 5,5s,5c,SE 4.0 44 32 不支持 -// 6,6s,7,8,SE2 4.7 44 32 32 -// 6,6s,7,8plus 5.5 44 44 32 -// X,XS,11Pro 5.8 44 32 32 -// XR,11 6.1 44 44 32 -// XS MAX,11Pro Max 6.5 44 44 32 -// 12mini 5.4 44 32 32 -// 12,12Pro 6.1 44 32 32 -// 12Pro Max 6.7 44 44 32 -// iPad iOS12之前是44,之后是50 -@property(class, nonatomic, readonly) CGFloat navBarHeight; -@property(class, nonatomic, readonly) UIEdgeInsets safeAreaInsets; -@property(class, nonatomic, readonly) CGRect statusBarFrame; -@property(class, nonatomic, readonly) UIWindow *keyWindow; +@property (class, nonatomic, readonly) BOOL is35InchScreen; + +@property (class, nonatomic, readonly) CGSize screenSizeFor67Inch; +@property (class, nonatomic, readonly) CGSize screenSizeFor65Inch; +@property (class, nonatomic, readonly) CGSize screenSizeFor61InchAndiPhone12; +@property (class, nonatomic, readonly) CGSize screenSizeFor61Inch; +@property (class, nonatomic, readonly) CGSize screenSizeFor58Inch; +@property (class, nonatomic, readonly) CGSize screenSizeFor55Inch; +@property (class, nonatomic, readonly) CGSize screenSizeFor54Inch; +@property (class, nonatomic, readonly) CGSize screenSizeFor47Inch; +@property (class, nonatomic, readonly) CGSize screenSizeFor40Inch; +@property (class, nonatomic, readonly) CGSize screenSizeFor35Inch; + +// 导航栏高度,包括竖屏,横屏,放大模式,非全屏模式 +// 机型\高度 尺寸 竖屏 横屏 放大模式 非全屏模式 +// 5,5s,5c,SE 4.0 44 32 不支持 56 +// 6,6s,7,8,SE2 4.7 44 32 32 56 +// 6,6s,7,8plus 5.5 44 44 32 56 +// X,XS,11Pro 5.8 44 32 32 56 +// XR,11 6.1 44 44 32 56 +// XS MAX,11Pro Max 6.5 44 44 32 56 +// 12mini 5.4 44 32 32 56 +// 12,12Pro 6.1 44 32 32 56 +// 12Pro Max 6.7 44 44 32 56 +// iPad iOS12之前是44,之后是50 56 +@property (class, nonatomic, readonly) CGFloat navBarHeight; +@property (class, nonatomic, readonly) CGFloat navBarHeight_nonFullScreen; +@property (class, nonatomic, readonly) CGFloat tabBarHeight; +@property (class, nonatomic, readonly) UIEdgeInsets safeAreaInsets; +@property (class, nonatomic, readonly) CGRect statusBarFrame; +@property (class, nonatomic, readonly) UIWindow *keyWindow; + +// 用于获取 isNotchedScreen 设备的 insets,注意对于 iPad Pro 11-inch 这种无刘海凹槽但却有使用 Home Indicator 的设备,它的 top 返回0,bottom 返回 safeAreaInsets.bottom 的值 ++ (UIEdgeInsets)safeAreaInsetsForDeviceWithNotch; @end diff --git a/GKNavigationBar/NavigationBar/GKNavigationBarConfigure.m b/GKNavigationBar/NavigationBar/GKNavigationBarConfigure.m index 29f1ac5..9646689 100644 --- a/GKNavigationBar/NavigationBar/GKNavigationBarConfigure.m +++ b/GKNavigationBar/NavigationBar/GKNavigationBarConfigure.m @@ -77,6 +77,13 @@ - (CGFloat)gk_fixedSpace { return DEVICE_WIDTH > 375.0f ? 20 : 16; } +- (NSBundle *)gk_libraryBundle { + NSBundle *bundle = [NSBundle bundleForClass:self.class]; + NSURL *bundleURL = [bundle URLForResource:@"GKNavigationBar" withExtension:@"bundle"]; + if (!bundleURL) return nil; + return [NSBundle bundleWithURL:bundleURL]; +} + @end @implementation GKNavigationBarConfigure (UIDevice) @@ -351,6 +358,37 @@ + (CGFloat)navBarHeight { } } ++ (CGFloat)navBarHeight_nonFullScreen { + return 56; +} + +static CGFloat tabBarHeight = -1; ++ (CGFloat)tabBarHeight { + if ([self isIPad]) { + if ([self isNotchedScreen]) { + tabBarHeight = 65; + }else { + if (GK_SYSTEM_VERSION >= 12.0) { + tabBarHeight = 50; + }else { + tabBarHeight = 49; + } + } + }else { + if (GK_IS_LANDSCAPE) { + if ([self isRegularScreen]) { + tabBarHeight = 49; + }else { + tabBarHeight = 32; + } + }else { + tabBarHeight = 49; + } + tabBarHeight += [self safeAreaInsetsForDeviceWithNotch].bottom; + } + return tabBarHeight; +} + + (UIEdgeInsets)safeAreaInsets { UIEdgeInsets safeAreaInsets = UIEdgeInsetsZero; if (@available(iOS 11.0, *)) { @@ -419,4 +457,32 @@ + (UIWindow *)keyWindow { return window; } ++ (UIEdgeInsets)safeAreaInsetsForDeviceWithNotch { + if (![self isNotchedScreen]) { + return UIEdgeInsetsZero; + } + + if ([self isIPad]) { + return UIEdgeInsetsMake(0, 0, 20, 0); + } + + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; + + switch (orientation) { + case UIInterfaceOrientationPortrait: + return UIEdgeInsetsMake(44, 0, 34, 0); + + case UIInterfaceOrientationPortraitUpsideDown: + return UIEdgeInsetsMake(34, 0, 44, 0); + + case UIInterfaceOrientationLandscapeLeft: + case UIInterfaceOrientationLandscapeRight: + return UIEdgeInsetsMake(0, 44, 21, 44); + + case UIInterfaceOrientationUnknown: + default: + return UIEdgeInsetsMake(44, 0, 34, 0); + } +} + @end diff --git a/GKNavigationBar/NavigationBar/GKNavigationBarDefine.h b/GKNavigationBar/NavigationBar/GKNavigationBarDefine.h index 1dc821c..0838051 100644 --- a/GKNavigationBar/NavigationBar/GKNavigationBarDefine.h +++ b/GKNavigationBar/NavigationBar/GKNavigationBarDefine.h @@ -40,10 +40,12 @@ #define GK_STATUSBAR_HEIGHT [GKNavigationBarConfigure statusBarFrame].size.height // 导航栏高度 #define GK_NAVBAR_HEIGHT [GKNavigationBarConfigure navBarHeight] +// 非全屏导航栏高度 +#define GK_NAVBAR_HEIGHT_NFS [GKNavigationBarConfigure navBarHeight_nonFullScreen] // 状态栏+导航栏高度 #define GK_STATUSBAR_NAVBAR_HEIGHT (GK_STATUSBAR_HEIGHT + GK_NAVBAR_HEIGHT) // tabbar高度 -#define GK_TABBAR_HEIGHT (GK_SAFEAREA_BTM + 49.0f) +#define GK_TABBAR_HEIGHT [GKNavigationBarConfigure tabBarHeight] // 导航栏间距,用于不同控制器之间的间距 static const CGFloat GKNavigationBarItemSpace = -1; diff --git a/GKNavigationBar/NavigationBar/UIImage+GKNavigationBar.m b/GKNavigationBar/NavigationBar/UIImage+GKNavigationBar.m index 63aa090..3503382 100644 --- a/GKNavigationBar/NavigationBar/UIImage+GKNavigationBar.m +++ b/GKNavigationBar/NavigationBar/UIImage+GKNavigationBar.m @@ -7,13 +7,13 @@ // #import "UIImage+GKNavigationBar.h" +#import "GKNavigationBarDefine.h" @implementation UIImage (GKNavigationBar) + (UIImage *)gk_imageNamed:(NSString *)name { - NSString *bundleName = [@"GKNavigationBar.bundle" stringByAppendingPathComponent:name]; - NSString *frameWorkName = [@"Frameworks/GKNavigationBar.framework/GKNavigationBar.bundle" stringByAppendingPathComponent:name]; - UIImage *image = [UIImage imageNamed:bundleName] ?: [UIImage imageNamed:frameWorkName]; + if (![GKConfigure gk_libraryBundle]) return [UIImage imageNamed:name]; + UIImage *image = [UIImage imageNamed:name inBundle:[GKConfigure gk_libraryBundle] compatibleWithTraitCollection:nil]; if (!image) image = [UIImage imageNamed:name]; return image; } diff --git a/GKNavigationBar/NavigationBar/UIViewController+GKNavigationBar.m b/GKNavigationBar/NavigationBar/UIViewController+GKNavigationBar.m index a5a6ef4..1ab2701 100644 --- a/GKNavigationBar/NavigationBar/UIViewController+GKNavigationBar.m +++ b/GKNavigationBar/NavigationBar/UIViewController+GKNavigationBar.m @@ -535,22 +535,45 @@ - (void)setupNavBarAppearance { if (self.gk_backStyle == GKNavigationBarBackStyleNone) { self.gk_backStyle = GKConfigure.backStyle; } + + self.gk_navTitle = nil; } - (void)setupNavBarFrame { + UIViewController *parentVC = self; + while (parentVC.parentViewController) { + parentVC = parentVC.parentViewController; + } + + CGFloat viewW = parentVC.view.frame.size.width; + CGFloat viewH = parentVC.view.frame.size.height; + if (viewW == 0 || viewH == 0) return; + + BOOL isNonFullScreen = self.presentingViewController && viewH < GK_SCREEN_HEIGHT; + CGFloat navBarH = 0.0f; if (GK_IS_iPad) { // iPad - navBarH = self.gk_statusBarHidden ? GK_NAVBAR_HEIGHT : GK_STATUSBAR_NAVBAR_HEIGHT; - }else if (GK_IS_LANDSCAPE) { // 横屏不显示状态栏 + if (isNonFullScreen) { + navBarH = GK_NAVBAR_HEIGHT_NFS; + self.gk_navigationBar.gk_nonFullScreen = YES; + }else { + navBarH = self.gk_statusBarHidden ? GK_NAVBAR_HEIGHT : GK_STATUSBAR_NAVBAR_HEIGHT; + } + }else if (GK_IS_LANDSCAPE) { // 横屏不显示状态栏,没有非全屏模式 navBarH = GK_NAVBAR_HEIGHT; }else { - if (GK_NOTCHED_SCREEN) { // 刘海屏手机 - navBarH = GK_SAFEAREA_TOP + GK_NAVBAR_HEIGHT; + if (isNonFullScreen) { + navBarH = GK_NAVBAR_HEIGHT_NFS; + self.gk_navigationBar.gk_nonFullScreen = YES; }else { - navBarH = self.gk_statusBarHidden ? GK_NAVBAR_HEIGHT : GK_STATUSBAR_NAVBAR_HEIGHT; + if (GK_NOTCHED_SCREEN) { // 刘海屏手机 + navBarH = GK_SAFEAREA_TOP + GK_NAVBAR_HEIGHT; + }else { + navBarH = self.gk_statusBarHidden ? GK_NAVBAR_HEIGHT : GK_STATUSBAR_NAVBAR_HEIGHT; + } } } - self.gk_navigationBar.frame = CGRectMake(0, 0, GK_SCREEN_WIDTH, navBarH); + self.gk_navigationBar.frame = CGRectMake(0, 0, viewW, navBarH); [self.gk_navigationBar layoutSubviews]; } diff --git a/GKNavigationBarExample/GKNavigationBarExample.xcodeproj/project.pbxproj b/GKNavigationBarExample/GKNavigationBarExample.xcodeproj/project.pbxproj index 89719f8..74765cb 100644 --- a/GKNavigationBarExample/GKNavigationBarExample.xcodeproj/project.pbxproj +++ b/GKNavigationBarExample/GKNavigationBarExample.xcodeproj/project.pbxproj @@ -22,6 +22,7 @@ 608FC6FF25469C9C003DB82F /* GKFloatTransition.m in Sources */ = {isa = PBXBuildFile; fileRef = 608FC6F625469C9C003DB82F /* GKFloatTransition.m */; }; 608FC70025469C9C003DB82F /* GKFloatView.m in Sources */ = {isa = PBXBuildFile; fileRef = 608FC6F725469C9C003DB82F /* GKFloatView.m */; }; 60975074254A70B200AE28CC /* GKGestureHandleConfigure.m in Sources */ = {isa = PBXBuildFile; fileRef = 60975073254A70B200AE28CC /* GKGestureHandleConfigure.m */; }; + 609E890D2644E3A300C15CB1 /* GKPresentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 609E890C2644E3A300C15CB1 /* GKPresentViewController.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 */; }; @@ -147,6 +148,8 @@ 60975072254A70B200AE28CC /* GKGestureHandleConfigure.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GKGestureHandleConfigure.h; sourceTree = ""; }; 60975073254A70B200AE28CC /* GKGestureHandleConfigure.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GKGestureHandleConfigure.m; sourceTree = ""; }; 60975077254A71BA00AE28CC /* GKGestureHandleDefine.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GKGestureHandleDefine.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 = ""; }; 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 = ""; }; @@ -468,6 +471,8 @@ 794AFC31242F07E900BECA1B /* GKBaseViewController.m */, 794AFC35242F4FB600BECA1B /* GKBaseNavigationController.h */, 794AFC36242F4FB600BECA1B /* GKBaseNavigationController.m */, + 609E890B2644E3A300C15CB1 /* GKPresentViewController.h */, + 609E890C2644E3A300C15CB1 /* GKPresentViewController.m */, ); path = BaseVC; sourceTree = ""; @@ -836,6 +841,7 @@ 796CF8BA236D7BBF00983E9B /* GKToutiaoVideoViewController.m in Sources */, 796CF8DD236D7BBF00983E9B /* GKDouyinHomeSearchViewController.m in Sources */, 796CF8C6236D7BBF00983E9B /* GKWYNewsProfileViewController.m in Sources */, + 609E890D2644E3A300C15CB1 /* GKPresentViewController.m in Sources */, 601BB2D5256CA96B001D59C8 /* GKDemoTransitionViewController.m in Sources */, 796CF8C1236D7BBF00983E9B /* GKWYMusicAccountViewController.m in Sources */, 602E1D53254A61D100ABC246 /* UIScrollView+GKGestureHandle.m in Sources */, diff --git a/GKNavigationBarExample/GKNavigationBarExample/Demo/BaseVC/GKBaseNavigationController.m b/GKNavigationBarExample/GKNavigationBarExample/Demo/BaseVC/GKBaseNavigationController.m index edcb3ba..bf35061 100644 --- a/GKNavigationBarExample/GKNavigationBarExample/Demo/BaseVC/GKBaseNavigationController.m +++ b/GKNavigationBarExample/GKNavigationBarExample/Demo/BaseVC/GKBaseNavigationController.m @@ -19,12 +19,12 @@ - (void)viewDidLoad { // Do any additional setup after loading the view. } -- (UIViewController *)childViewControllerForStatusBarHidden { - return self.topViewController; -} - -- (UIViewController *)childViewControllerForStatusBarStyle { - return self.topViewController; -} +//- (UIViewController *)childViewControllerForStatusBarHidden { +// return self.topViewController; +//} +// +//- (UIViewController *)childViewControllerForStatusBarStyle { +// return self.topViewController; +//} @end diff --git a/GKNavigationBarExample/GKNavigationBarExample/Demo/BaseVC/GKBaseViewController.m b/GKNavigationBarExample/GKNavigationBarExample/Demo/BaseVC/GKBaseViewController.m index 0e8b86f..3b71575 100644 --- a/GKNavigationBarExample/GKNavigationBarExample/Demo/BaseVC/GKBaseViewController.m +++ b/GKNavigationBarExample/GKNavigationBarExample/Demo/BaseVC/GKBaseViewController.m @@ -19,4 +19,12 @@ - (void)viewDidLoad { // Do any additional setup after loading the view. } +- (BOOL)prefersStatusBarHidden { + return self.gk_statusBarHidden; +} + +- (UIStatusBarStyle)preferredStatusBarStyle { + return self.gk_statusBarStyle; +} + @end diff --git a/GKNavigationBarExample/GKNavigationBarExample/Demo/BaseVC/GKPresentViewController.h b/GKNavigationBarExample/GKNavigationBarExample/Demo/BaseVC/GKPresentViewController.h new file mode 100644 index 0000000..38254e3 --- /dev/null +++ b/GKNavigationBarExample/GKNavigationBarExample/Demo/BaseVC/GKPresentViewController.h @@ -0,0 +1,17 @@ +// +// GKPresentViewController.h +// GKNavigationBarExample +// +// Created by gaokun on 2021/5/7. +// Copyright © 2021 QuintGao. All rights reserved. +// + +#import "GKBaseViewController.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface GKPresentViewController : GKBaseViewController + +@end + +NS_ASSUME_NONNULL_END diff --git a/GKNavigationBarExample/GKNavigationBarExample/Demo/BaseVC/GKPresentViewController.m b/GKNavigationBarExample/GKNavigationBarExample/Demo/BaseVC/GKPresentViewController.m new file mode 100644 index 0000000..0b5dfe9 --- /dev/null +++ b/GKNavigationBarExample/GKNavigationBarExample/Demo/BaseVC/GKPresentViewController.m @@ -0,0 +1,38 @@ +// +// GKPresentViewController.m +// GKNavigationBarExample +// +// Created by gaokun on 2021/5/7. +// Copyright © 2021 QuintGao. All rights reserved. +// + +#import "GKPresentViewController.h" + +@interface GKPresentViewController () + +@end + +@implementation GKPresentViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.view.backgroundColor = UIColor.whiteColor; + self.gk_navTitle = @"presentVC"; + self.gk_navRightBarButtonItem = [UIBarButtonItem gk_itemWithTitle:@"关闭" target:self action:@selector(close)]; + self.gk_navBackgroundColor = UIColor.blueColor; +} + +- (void)viewWillLayoutSubviews { + [super viewWillLayoutSubviews]; + + NSLog(@"%@", NSStringFromCGRect(UIScreen.mainScreen.bounds)); + NSLog(@"%@", NSStringFromCGRect(self.view.frame)); + NSLog(@"%@", NSStringFromCGRect(self.navigationController.navigationBar.frame)); +} + +- (void)close { + [self dismissViewControllerAnimated:YES completion:nil]; +} + +@end diff --git a/GKNavigationBarExample/GKNavigationBarExample/Demo/GKMainViewController.m b/GKNavigationBarExample/GKNavigationBarExample/Demo/GKMainViewController.m index c6f64ee..7f5fd69 100644 --- a/GKNavigationBarExample/GKNavigationBarExample/Demo/GKMainViewController.m +++ b/GKNavigationBarExample/GKNavigationBarExample/Demo/GKMainViewController.m @@ -13,6 +13,7 @@ #import "GKDouyinHomeViewController.h" #import "GKWXViewController.h" #import "UINavigationController+GKGestureHandle.h" +#import "GKPresentViewController.h" @interface GKMainViewController () @@ -36,7 +37,8 @@ - (NSArray *)dataSource { @"今日头条", @"网易云音乐", @"网易新闻", - @"微信(自定义push,pop)"]; + @"微信(自定义push,pop)", + @"present非全屏"]; } return _dataSource; } @@ -52,8 +54,8 @@ - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; - self.gk_navigationItem.title = @"MainVC"; -// self.gk_navBackgroundColor = [UIColor redColor]; +// self.gk_navigationItem.title = @"MainVC"; + self.gk_navBackgroundColor = [UIColor redColor]; self.gk_statusBarStyle = UIStatusBarStyleLightContent; self.gk_navTitleFont = [UIFont systemFontOfSize:18.0f]; @@ -165,6 +167,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath GKWXViewController *wxVC = [GKWXViewController new]; wxVC.modalPresentationStyle = UIModalPresentationFullScreen; [self presentViewController:wxVC animated:YES completion:nil]; + }else if (indexPath.row == 11) { + UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[GKPresentViewController new]]; + [self presentViewController:nav animated:YES completion:nil]; } } } diff --git a/README.md b/README.md index ab3cbb2..ac647d4 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Swift版本请看这里 → [GKNavigationBarSwift](https://github.com/QuintGao/G return self; } ``` -#### 4、Xcode 11.4 在调试的时候会出现状态栏样式改变不了的情况 +#### 4、状态栏相关方法无效? 解决办法:在基类控制器里实现下面两个方法 ``` - (BOOL)prefersStatusBarHidden { @@ -164,6 +164,7 @@ configure.shiledGuestureVCs = @[NSClassFromString(@"TZPhotoPickerController"), @ ## 版本记录 +* 1.5.3 - 2021.05.07 修复直接设置背景色无效的问题#71,#74,增加对非全屏的支持 * 1.5.2 - 2021.04.06 增加协议方法,解决返回手势与WKWebView中的手势冲突问题 * 1.5.1 - 2021.03.09 返回手势优化,新增backStyle对应的image,可全局配置 * 1.5.0 - 2021.03.05