NJKScrollFullScreen

像 Facebook 应用程序一样滚动到全屏。「Scroll to full screen like Facebook app」

Github stars Tracking Chart

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

1. Instance NJKScrollFullScreen

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

License

MIT license.

Main metrics

Overview
Name With Ownerninjinkun/NJKScrollFullScreen
Primary LanguageObjective-C
Program languageObjective-C (Language Count: 2)
Platform
License:MIT License
所有者活动
Created At2014-01-04 08:09:07
Pushed At2019-12-05 06:28:51
Last Commit At2015-06-30 20:59:06
Release Count8
Last Release Namev0.2.6 (Posted on 2015-06-30 19:49:09)
First Release Namev0.1 (Posted on 2014-01-04 18:33:47)
用户参与
Stargazers Count0.9k
Watchers Count40
Fork Count92
Commits Count56
Has Issues Enabled
Issues Count11
Issue Open Count6
Pull Requests Count18
Pull Requests Open Count4
Pull Requests Close Count2
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private