NJKScrollFullScreen 0.2.6

NJKScrollFullScreen 0.2.6

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布上一次发布2015 年 6 月

维护。



  • 作者
  • ninjinkun

NJKScrollFullSreen

NJKScrollFullSreen 是一个类似 Facebook App 的全屏滚动库。

此仓库包含全屏代理和全屏 UI 行为模块。

  • NJKScrollFullSreen
    • 一个简单的 UIScrollViewDelegate 包装器。当需要全屏时,它调用代理方法。
  • UIViewController+NJKFullScreenSupport
    • 向 UIViewController 添加全屏行为。

这些模块是独立的。您可以在不使用 UIViewController+NJKFullScreenSupport 的情况下实现自己的自定义全屏行为。NJKScrollFullSreen 不仅适用于 UIScrollView,还适用于 UIWebView 和 UITableView。

要求

  • iOS 5.0 或更高版本
  • ARC

安装

使用方法

1. 实例化 NJKScrollFullScreen

在您的视图控制器上实例化并设置 UIScrollViewDelegate。如果您设置了 scrollViewDelegate,则 NJKScrollFullScreen 应作为代理对象执行。

- (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. 实现代理方法

- (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. 实现全屏行为

您可以选择 UIViewController+NJKFullScreenSupport 或您自己的视图管理代码。

使用 UIViewController+NJKFullScreenSupport.h

#import "UIViewController+NJKFullScreenSupport.h"

或者,您可以像下面一样实现自己的全屏行为。

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

许可证

MIT 许可证.