NJKScrollFullSrceen
NJKScrollFullSrceen is Facebook App like scroll to full screen library.
This repository consists of full screen delegate and full screen UI behaivior module.
NJKScrollFullScreen
- Simple UIScrollViewDelegate wrapper. It called delegate methods when full screen wanted.
UIViewController+NJKFullScreenSupport
- Add full screen behaivior to UIViewController.
These modules are individual. You can implement your own customized full screen behavior without UIViewController+NJKFullScreenSupport
.
NJKScrollFullSrceen
can apply not only UIScrollView but also UIWebView and UITableView.
Requirements
- iOS 5.0 or later
- ARC
Install
CocoaPods
pod 'NJKScrollFullScreen'
Usage
NJKScrollFullScreen
1. Instance Instance and set UIScrollViewDelegate
on your view controller. If you set scrollViewDelegate
, NJKScrollFullScreen
suould perform as a proxy object.
- (void)viewDidLoad
{
[super viewDidLoad];
_scrollProxy = [[NJKScrollFullScreen alloc] initWithForwardTarget:self]; // UIScrollViewDelegate and UITableViewDelegate methods proxy to ViewController
self.tableView.delegate = (id)_scrollProxy; // cast for surpress incompatible warnings
_scrollProxy.delegate = self;
}
2. Implement delegate methods
- (void)scrollFullScreen:(NJKScrollFullScreen *)proxy scrollViewDidScrollUp:(CGFloat)deltaY
{
[self moveNavigationBar:deltaY animated:YES];
}
- (void)scrollFullScreen:(NJKScrollFullScreen *)proxy scrollViewDidScrollDown:(CGFloat)deltaY
{
[self moveNavigationBar:deltaY animated:YES];
}
- (void)scrollFullScreenScrollViewDidEndDraggingScrollUp:(NJKScrollFullScreen *)proxy
{
[self hideNavigationBar:YES];
}
- (void)scrollFullScreenScrollViewDidEndDraggingScrollDown:(NJKScrollFullScreen *)proxy
{
[self showNavigationBar:YES];
}
3. Implement full screen behavior
You can choose UIViewController+NJKFullScreenSupport
or your own view management code.
Use UIViewController+NJKFullScreenSupport.h
.
#import "UIViewController+NJKFullScreenSupport.h"
Or you can implement own full screen behavior like below.
- (void)showNavigationBar:(BOOL)animated
{
CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
[self setNavigationBarOriginY:statusBarHeight animated:animated];
}
- (void)hideNavigationBar:(BOOL)animated
{
[self setNavigationBarOriginY:0 animated:animated];
}
- (void)moveNavigationBar:(CGFloat)deltaY animated:(BOOL)animated
{
CGRect frame = self.navigationController.navigationBar.frame;
CGFloat nextY = frame.origin.y + deltaY;
[self setNavigationBarOriginY:nextY animated:animated];
}
- (void)setNavigationBarOriginY:(CGFloat)y animated:(BOOL)animated
{
CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
CGRect frame = self.navigationController.navigationBar.frame;
CGFloat navigationBarHeight = frame.size.height;
frame.origin.y = fmin(fmax(y, navigationBarHeight), statusBarHeight); // limit over moving
[UIView animateWithDuration:animated ? 0.1 : 0 animations:^{
self.navigationController.navigationBar.frame = frame;
}];
}