diff --git a/NYTPhotoViewer/NYTPhotosViewController.m b/NYTPhotoViewer/NYTPhotosViewController.m index 7255f6ce..077bf5d1 100644 --- a/NYTPhotoViewer/NYTPhotosViewController.m +++ b/NYTPhotoViewer/NYTPhotosViewController.m @@ -131,6 +131,20 @@ - (void)viewDidLoad { self.transitionController.endingView = endingView; } +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + if ([_delegate respondsToSelector:@selector(photosViewController:viewWillAppear:)]) { + [_delegate photosViewController:self viewWillAppear:animated]; + } +} + +- (void)viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; + if ([_delegate respondsToSelector:@selector(photosViewController:viewWillDisappear:)]) { + [_delegate photosViewController:self viewWillDisappear:animated]; + } +} + - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; @@ -142,12 +156,41 @@ - (void)viewDidAppear:(BOOL)animated { - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; - self.pageViewController.view.frame = self.view.bounds; - self.overlayView.frame = self.view.bounds; + CGRect frame = self.view.bounds; + if (!self.prefersStatusBarHidden) { + CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height; + frame.origin.y = statusBarHeight; + frame.size.height -= statusBarHeight; + } + self.pageViewController.view.frame = frame; + self.overlayView.frame = frame; } - (BOOL)prefersStatusBarHidden { - return YES; + BOOL result; + switch (self.statusBarMode) { + case NYTPhotoViewerStatusBarModeDynamic: + result = self.view.safeAreaInsets.top == 0; + break; + case NYTPhotoViewerStatusBarModeHidden: + result = true; + break; + case NYTPhotoViewerStatusBarModeShown: + result = false; + break; + } + return result; +} + +- (void)viewSafeAreaInsetsDidChange { + if (self.statusBarMode == NYTPhotoViewerStatusBarModeDynamic) { + [self setNeedsStatusBarAppearanceUpdate]; + } + [super viewSafeAreaInsetsDidChange]; +} + +- (UIStatusBarStyle)preferredStatusBarStyle { + return UIStatusBarStyleLightContent; } - (BOOL)prefersHomeIndicatorAutoHidden { diff --git a/NYTPhotoViewer/include/NYTPhotosViewController.h b/NYTPhotoViewer/include/NYTPhotosViewController.h index 11cbca67..e5aea1da 100644 --- a/NYTPhotoViewer/include/NYTPhotosViewController.h +++ b/NYTPhotoViewer/include/NYTPhotosViewController.h @@ -41,6 +41,12 @@ extern NSString * const NYTPhotosViewControllerDidDismissNotification; @interface NYTPhotosViewController : UIViewController +typedef NS_ENUM(NSUInteger, NYTPhotoViewerStatusBarMode) { + NYTPhotoViewerStatusBarModeDynamic, /* hide statusbar when view.safeArea.top == 0 */ + NYTPhotoViewerStatusBarModeHidden, + NYTPhotoViewerStatusBarModeShown +}; + /** * The pan gesture recognizer used for panning to dismiss the photo. Disable to stop the pan-to-dismiss behavior. */ @@ -75,6 +81,12 @@ extern NSString * const NYTPhotosViewControllerDidDismissNotification; */ @property (nonatomic, readonly, nullable) NYTPhotosOverlayView *overlayView; +/** + * This determines whether we display the status bar or not + * Defaults to NYTPhotoViewerStatusBarModeDynamic. + */ +@property (nonatomic) NYTPhotoViewerStatusBarMode statusBarMode; + /** * The left bar button item overlaying the photo. */ @@ -177,6 +189,20 @@ extern NSString * const NYTPhotosViewControllerDidDismissNotification; @optional +/** + * Called when the view is about to made visible. + * + * @param photosViewController The `NYTPhotosViewController` instance that sent the delegate message. + */ +- (void)photosViewController:(NYTPhotosViewController *)photosViewController viewWillAppear:(BOOL)animated; + +/** + * Called when the view is dismissed, covered or otherwise hidden. + * + * @param photosViewController The `NYTPhotosViewController` instance that sent the delegate message. + */ +- (void)photosViewController:(NYTPhotosViewController *)photosViewController viewWillDisappear:(BOOL)animated; + /** * Called when a new photo is displayed through a swipe gesture. * diff --git a/scripts/bootstrap b/scripts/bootstrap index 8525e5eb..f17329b7 100755 --- a/scripts/bootstrap +++ b/scripts/bootstrap @@ -11,6 +11,8 @@ fi cd "$(dirname "$0")/../Examples" -bundle config set path 'vendor/bundle' +# uncomment the following if you get errors about not having access to the system's install +# bundle config --local path 'vendor/bundle' + bundle install bundle exec pod install