NJKScrollFullScreen

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

Github星跟蹤圖

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.

主要指標

概覽
名稱與所有者ninjinkun/NJKScrollFullScreen
主編程語言Objective-C
編程語言Objective-C (語言數: 2)
平台
許可證MIT License
所有者活动
創建於2014-01-04 08:09:07
推送於2019-12-05 06:28:51
最后一次提交2015-06-30 20:59:06
發布數8
最新版本名稱v0.2.6 (發布於 2015-06-30 19:49:09)
第一版名稱v0.1 (發布於 2014-01-04 18:33:47)
用户参与
星數0.9k
關注者數40
派生數92
提交數56
已啟用問題?
問題數11
打開的問題數6
拉請求數18
打開的拉請求數4
關閉的拉請求數2
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?