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]; }]; }