Skip to content

Commit

Permalink
状态栏适配优化
Browse files Browse the repository at this point in the history
  • Loading branch information
QuintGao committed Dec 6, 2021
1 parent cf5a9e6 commit bdee61e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion GKPhotoBrowser.podspec
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
18 changes: 12 additions & 6 deletions GKPhotoBrowser/Core/GKPhotoBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ @interface GKPhotoBrowser()<UIScrollViewDelegate, UIGestureRecognizerDelegate>
/// 20200312 用于防止多次addObserver,添加监听UIDeviceOrientationDidChangeNotification通知的flag
@property(nonatomic, assign) BOOL isOrientationNotiObserverAdded;

/// 状态栏处理
@property (nonatomic, assign) BOOL statusBarAppearance;

@end

@implementation GKPhotoBrowser
Expand Down Expand Up @@ -112,6 +115,12 @@ - (instancetype)initWithPhotos:(NSArray<GKPhoto *> *)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;
}
Expand Down Expand Up @@ -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)];
Expand All @@ -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)];
Expand Down Expand Up @@ -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];
Expand Down
7 changes: 6 additions & 1 deletion GKPhotoBrowserDemo/GKPhotoBrowserDemo/Classes/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 0 additions & 2 deletions GKPhotoBrowserDemo/GKPhotoBrowserDemo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bdee61e

Please sign in to comment.