Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 'statusBarMode' to drive whether the status bar is hidden or not. #336

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
2 changes: 2 additions & 0 deletions Examples/Sources/ObjC/NYTViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ - (IBAction)imageButtonTapped:(id)sender {

NYTPhotosViewController *photosViewController = [[NYTPhotosViewController alloc] initWithDataSource:self.dataSource initialPhoto:nil delegate:self];

photosViewController.underStatusBar = YES;

[self presentViewController:photosViewController animated:YES completion:nil];

[self updateImagesOnPhotosViewController:photosViewController afterDelayWithDataSource:self.dataSource];
Expand Down
20 changes: 20 additions & 0 deletions NYTPhotoViewer/NYTPhotosViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ extern NSString * const NYTPhotosViewControllerDidDismissNotification;
*/
@property (nonatomic, readonly, nullable) NYTPhotosOverlayView *overlayView;

/**
* Shows all content under status bar frame. Default NO.
mr-fixit marked this conversation as resolved.
Show resolved Hide resolved
*/
@property (nonatomic) BOOL underStatusBar;

/**
* The left bar button item overlaying the photo.
*/
Expand Down Expand Up @@ -177,6 +182,21 @@ extern NSString * const NYTPhotosViewControllerDidDismissNotification;

@optional

/**
* Called when the view is about to made visible.
*
* @param photosViewController The `NYTPhotosViewController` instance that sent the delegate message.
mr-fixit marked this conversation as resolved.
Show resolved Hide resolved
* @param animated
*/
- (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.
*
Expand Down
30 changes: 27 additions & 3 deletions NYTPhotoViewer/NYTPhotosViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -142,12 +156,22 @@ - (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.underStatusBar) {
CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;;
mr-fixit marked this conversation as resolved.
Show resolved Hide resolved
frame.origin.y = statusBarHeight;
frame.size.height -= statusBarHeight;
}
self.pageViewController.view.frame = frame;
self.overlayView.frame = frame;
}

- (BOOL)prefersStatusBarHidden {
return YES;
return !self.underStatusBar;
}

- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
mr-fixit marked this conversation as resolved.
Show resolved Hide resolved
}

- (BOOL)prefersHomeIndicatorAutoHidden {
Expand Down