From e3a04138f73eafde91db86d521be93ac090512e3 Mon Sep 17 00:00:00 2001 From: chimingzi Date: Wed, 24 Apr 2019 16:50:43 +0800 Subject: [PATCH] =?UTF-8?q?20190424=20=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=85=A8?= =?UTF-8?q?=E5=B1=8F=E5=B1=95=E7=A4=BA=E5=9B=BE=E7=89=87=E6=97=B6=E5=85=81?= =?UTF-8?q?=E8=AE=B8=E9=9A=90=E8=97=8F=E7=8A=B6=E6=80=81=E6=A0=8F=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD.=20=E5=8F=82=E8=80=83=E8=B5=84=E6=96=99:[?= =?UTF-8?q?=E4=BD=9C=E8=80=85:=E5=94=90=E5=B7=A7=20=E4=B9=A6=E7=B1=8D:iOS?= =?UTF-8?q?=E5=BC=80=E5=8F=91=E8=BF=9B=E9=98=B6]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ESPictureBrowser/ESPictureBrowser.h | 7 +++++++ .../ESPictureBrowser/ESPictureBrowser.m | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/ESPictureBrowserDemo/ESPictureBrowserDemo/ESPictureBrowser/ESPictureBrowser.h b/ESPictureBrowserDemo/ESPictureBrowserDemo/ESPictureBrowser/ESPictureBrowser.h index e709d87..e6d5474 100644 --- a/ESPictureBrowserDemo/ESPictureBrowserDemo/ESPictureBrowser/ESPictureBrowser.h +++ b/ESPictureBrowserDemo/ESPictureBrowserDemo/ESPictureBrowser/ESPictureBrowser.h @@ -38,6 +38,13 @@ - (NSString *)pictureView:(ESPictureBrowser *)pictureBrowser highQualityUrlStringForIndex:(NSInteger)index; @optional +/** + 是否允许在打开图片浏览器时隐藏状态栏 + + @param pictureBrowser 图片浏览器 + @return 是否允许的布尔值 + */ +-(BOOL)pictureViewShouldAllowHideStatusBar:(ESPictureBrowser *)pictureBrowser; /** 获取对应索引的视图 diff --git a/ESPictureBrowserDemo/ESPictureBrowserDemo/ESPictureBrowser/ESPictureBrowser.m b/ESPictureBrowserDemo/ESPictureBrowserDemo/ESPictureBrowser/ESPictureBrowser.m index db50adc..d976059 100644 --- a/ESPictureBrowserDemo/ESPictureBrowserDemo/ESPictureBrowser/ESPictureBrowser.m +++ b/ESPictureBrowserDemo/ESPictureBrowserDemo/ESPictureBrowser/ESPictureBrowser.m @@ -41,6 +41,8 @@ @interface ESPictureBrowser() @property (nonatomic, weak) UILabel *pageTextLabel; /// 消失的 tap 手势 @property (nonatomic, weak) UITapGestureRecognizer *dismissTapGes; +/// 唤起照片浏览器前的keywindow的层级,用于隐藏状态栏 +@property(nonatomic, assign) CGFloat windowLevelBeforeBrowserShown; @end @@ -107,6 +109,15 @@ - (void)showFromView:(UIView *)fromView picturesCount:(NSInteger)picturesCount c [self setPageText:currentPictureIndex]; // 添加到 window 上 [[UIApplication sharedApplication].keyWindow addSubview:self]; + // 隐藏状态栏 + if([_delegate respondsToSelector:@selector(pictureViewShouldAllowHideStatusBar:)]) + { + if([_delegate pictureViewShouldAllowHideStatusBar:self]) + { + self.windowLevelBeforeBrowserShown = [UIApplication sharedApplication].keyWindow.windowLevel; + [UIApplication sharedApplication].keyWindow.windowLevel = UIWindowLevelAlert; + } + } // 计算 scrollView 的 contentSize self.scrollView.contentSize = CGSizeMake(picturesCount * _scrollView.frame.size.width, _scrollView.frame.size.height); // 滚动到指定位置 @@ -163,6 +174,10 @@ - (void)dismiss { self.backgroundColor = [UIColor clearColor]; self.pageTextLabel.alpha = 0; } completionBlock:^{ + // 恢复状态栏 + if([self.delegate respondsToSelector:@selector(pictureViewShouldAllowHideStatusBar:)] + && [self.delegate pictureViewShouldAllowHideStatusBar:self]) + [UIApplication sharedApplication].keyWindow.windowLevel = self.windowLevelBeforeBrowserShown; [self removeFromSuperview]; }]; }