diff --git a/GKPhotoBrowser.podspec b/GKPhotoBrowser.podspec index c4f415c1..4f643820 100644 --- a/GKPhotoBrowser.podspec +++ b/GKPhotoBrowser.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "GKPhotoBrowser" - s.version = "2.3.3" + s.version = "2.3.4" s.summary = "iOS自定义图片浏览器,支持CocoaPods" s.homepage = "https://github.com/QuintGao/GKPhotoBrowser" s.license = "MIT" diff --git a/GKPhotoBrowser/Core/GKPhotoBrowser.m b/GKPhotoBrowser/Core/GKPhotoBrowser.m index 839b9fc9..a033a832 100644 --- a/GKPhotoBrowser/Core/GKPhotoBrowser.m +++ b/GKPhotoBrowser/Core/GKPhotoBrowser.m @@ -77,6 +77,9 @@ @interface GKPhotoBrowser() /// 20200312 用于防止多次addObserver,添加监听UIDeviceOrientationDidChangeNotification通知的flag @property(nonatomic, assign) BOOL isOrientationNotiObserverAdded; +/// 状态栏处理 +@property (nonatomic, assign) BOOL statusBarAppearance; + @end @implementation GKPhotoBrowser @@ -112,6 +115,12 @@ - (instancetype)initWithPhotos:(NSArray *)photos currentIndex:(NSInte if (imageManagerClass) { self.imageProtocol = [imageManagerClass new]; } + + // 状态栏外观处理 + NSDictionary *infoDict = [NSBundle mainBundle].infoDictionary; + BOOL hasKey = [infoDict.allKeys containsObject:@"UIViewControllerBasedStatusBarAppearance"]; + BOOL appearance = [[infoDict objectForKey:@"UIViewControllerBasedStatusBarAppearance"] boolValue]; + self.statusBarAppearance = (hasKey && appearance) || !hasKey; } return self; } @@ -273,8 +282,7 @@ - (void)setShowStyle:(GKPhotoBrowserShowStyle)showStyle { - (void)setIsStatusBarShow:(BOOL)isStatusBarShow { _isStatusBarShow = isStatusBarShow; - BOOL statusBarAppearance = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"] boolValue]; - if (statusBarAppearance) { + if (self.statusBarAppearance) { if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) { [self prefersStatusBarHidden]; [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)]; @@ -290,8 +298,7 @@ - (void)setIsStatusBarShow:(BOOL)isStatusBarShow { - (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle { _statusBarStyle = statusBarStyle; - BOOL statusBarAppearance = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"] boolValue]; - if (statusBarAppearance) { + if (self.statusBarAppearance) { if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) { [self prefersStatusBarHidden]; [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)]; @@ -616,8 +623,7 @@ - (void)dismissAnimated:(BOOL)animated { // 移除屏幕旋转监听 [self delDeviceOrientationObserver]; - BOOL statusBarAppearance = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"] boolValue]; - if (!statusBarAppearance) { + if (!self.statusBarAppearance) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" [[UIApplication sharedApplication] setStatusBarStyle:self.originStatusBarStyle]; diff --git a/GKPhotoBrowserDemo/GKPhotoBrowserDemo/Classes/AppDelegate.m b/GKPhotoBrowserDemo/GKPhotoBrowserDemo/Classes/AppDelegate.m index 5d8c8ff2..22bea368 100644 --- a/GKPhotoBrowserDemo/GKPhotoBrowserDemo/Classes/AppDelegate.m +++ b/GKPhotoBrowserDemo/GKPhotoBrowserDemo/Classes/AppDelegate.m @@ -40,14 +40,19 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( [self.window makeKeyAndVisible]; + + BOOL hasKey = [[NSBundle mainBundle].infoDictionary.allKeys containsObject:@"UIViewControllerBasedStatusBarAppearance"]; + BOOL statusBarAppearance = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"] boolValue]; - if (!statusBarAppearance) { + + if (hasKey && !statusBarAppearance) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" [[UIApplication sharedApplication] setStatusBarHidden:NO]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; #pragma clang diagnostic pop } + return YES; } diff --git a/GKPhotoBrowserDemo/GKPhotoBrowserDemo/Info.plist b/GKPhotoBrowserDemo/GKPhotoBrowserDemo/Info.plist index 49107200..c487cab7 100644 --- a/GKPhotoBrowserDemo/GKPhotoBrowserDemo/Info.plist +++ b/GKPhotoBrowserDemo/GKPhotoBrowserDemo/Info.plist @@ -43,8 +43,6 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight - UIViewControllerBasedStatusBarAppearance - UISupportedInterfaceOrientations~ipad UIInterfaceOrientationPortrait diff --git a/README.md b/README.md index 119d4ccc..0fb42d1b 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,7 @@ GKPhotoBrowser一个可高度自定义的图片浏览器,demo里面实现的 ## 更新 ``` +2021.12.06 2.3.4版本,状态栏适配优化 2021.10.12 2.3.3版本,当View controller-based status bar appearance设置为NO时适配状态栏 # 126 2021.08.05 2.3.2版本,优化pageControl的显示 2021.06.07 2.3.1版本,修复放大后滑动两张图片再返回显示异常的问题 #123