Skip to content

Commit

Permalink
修复设置背景色无效问题#71 #73,增加对非全屏的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
QuintGao committed May 7, 2021
1 parent 4defd6b commit 2575569
Show file tree
Hide file tree
Showing 15 changed files with 238 additions and 61 deletions.
2 changes: 1 addition & 1 deletion GKNavigationBar.podspec
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
3 changes: 3 additions & 0 deletions GKNavigationBar/NavigationBar/GKCustomNavigationBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion GKNavigationBar/NavigationBar/GKCustomNavigationBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}];
Expand Down
84 changes: 46 additions & 38 deletions GKNavigationBar/NavigationBar/GKNavigationBarConfigure.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ NS_ASSUME_NONNULL_BEGIN
/// 获取当前item修复间距
- (CGFloat)gk_fixedSpace;

/// 获取bundle
- (NSBundle *)gk_libraryBundle;

@end

// from QMUI
Expand All @@ -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

Expand Down
66 changes: 66 additions & 0 deletions GKNavigationBar/NavigationBar/GKNavigationBarConfigure.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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, *)) {
Expand Down Expand Up @@ -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
4 changes: 3 additions & 1 deletion GKNavigationBar/NavigationBar/GKNavigationBarDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions GKNavigationBar/NavigationBar/UIImage+GKNavigationBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
35 changes: 29 additions & 6 deletions GKNavigationBar/NavigationBar/UIViewController+GKNavigationBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -147,6 +148,8 @@
60975072254A70B200AE28CC /* GKGestureHandleConfigure.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GKGestureHandleConfigure.h; sourceTree = "<group>"; };
60975073254A70B200AE28CC /* GKGestureHandleConfigure.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GKGestureHandleConfigure.m; sourceTree = "<group>"; };
60975077254A71BA00AE28CC /* GKGestureHandleDefine.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GKGestureHandleDefine.h; sourceTree = "<group>"; };
609E890B2644E3A300C15CB1 /* GKPresentViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GKPresentViewController.h; sourceTree = "<group>"; };
609E890C2644E3A300C15CB1 /* GKPresentViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GKPresentViewController.m; sourceTree = "<group>"; };
60B3D7A6258AFBAF003A4C7C /* GKDemo005ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GKDemo005ViewController.h; sourceTree = "<group>"; };
60B3D7A7258AFBAF003A4C7C /* GKDemo005ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GKDemo005ViewController.m; sourceTree = "<group>"; };
60B70D75256F8A11008D62FC /* GKDemo004ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GKDemo004ViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -468,6 +471,8 @@
794AFC31242F07E900BECA1B /* GKBaseViewController.m */,
794AFC35242F4FB600BECA1B /* GKBaseNavigationController.h */,
794AFC36242F4FB600BECA1B /* GKBaseNavigationController.m */,
609E890B2644E3A300C15CB1 /* GKPresentViewController.h */,
609E890C2644E3A300C15CB1 /* GKPresentViewController.m */,
);
path = BaseVC;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 2575569

Please sign in to comment.