Giter VIP home page Giter VIP logo

njkscrollfullscreen's Introduction

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.

njkscrollfullscreen's People

Contributors

debris avatar jgrana avatar konomae avatar ninjinkun avatar sasaujp avatar siong1987 avatar star-zero avatar tonnyxu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

njkscrollfullscreen's Issues

Custom font removed?

I use a custom font in my nav bar - [[UINavigationBar appearance] setTitleTextAttributes:navTitleAttributes];.

The font seems to be reset to the default when the nav bar comes back.

uitableview delegate methods

uitableview delegate methods are not getting called after setting tableview delegate to scroll proxy.

e.g.

  • (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

In the demo project after calling

[self.tableView reloadData];

I thought that there is something wrong with method forwarding implementation.

But by calling

        [((UITableViewController <UITableViewDelegate>*)(self.tableView.delegate)) tableView:self.tableView heightForHeaderInSection:0];

instead of reloading tableview that method is forwarded correctly. Hence i can confirm that method forwarding is working.

It might be that uitableview has it's own delegate check mechanism internally and ignores to call delegate methods with current implementation. It sees an object conforming to UIScrollViewDelegate but not UITableViewDelegate.

Autolayout

Hi,
i try to use it on uitableview inside uiviewcontroller with auto layout it's didn't work any advice for this case please

NavBar Buttons & Color broken after Rotation

Hi,

just tested the last official commit made on the main branch 4 days ago.

The same problems for the NavBar after device rotation exists.

1st Problem

Steps to reproduce:

  • Use a common UINavigationBar with UIBarButtonItems
  • Scroll down, so the NavBar is hidden
  • Rotate the device to landscape

Expected:
Seeing the UINavigationBar and it's UIBarButtonItems again

Result:
NavBar is visible again (as wanted), but the UIBarButtonItems are hidden.

screen shot 2014-03-25 at 11 47 05

2nd Problem

Steps to reproduce:

  • Same as above
  • Additionally: Try to scroll up

Result:
The UIBarButtonItems appear again. But their color changed to yellow instead of white (white is expected and previously set). Like mentioned here before: #8 (comment)

44dc4518-97eb-11e3-9da3-6852ce537f4e

Related Code:
In UIViewController+NJKFullScreenSupport.m, in (void)setNavigationBarOriginY:(CGFloat)y animated:(BOOL)animated.

Commenting out setting the tintColor removes the Yellow coloring after the button return. The 1st problem seems to be related to view.alpha restoration. You are restoring the Bar's alpha but not of the Buttons..

for (UIView *view in self.navigationController.navigationBar.subviews) {
            index++;
            if (index == 1 || view.hidden || view.alpha <= 0.0f) continue; // this logic is somehow broken
            view.alpha = alpha;
        }
        if (NJK_IS_RUNNING_IOS7) { // following leads to yellow buttons
            // fade bar buttons
            UIColor *tintColor = self.navigationController.navigationBar.tintColor;
            if (tintColor) {
                CGFloat *components = (CGFloat *)CGColorGetComponents(tintColor.CGColor);
                self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:components[0] green:components[1] blue:components[2] alpha:alpha];
            }
        }

Cheers,
Frederik

custom titleview

Currently custom title view for uinavigationbar is not supported for the fading effect.

TabBar animation is broken

UIViewController+NJKFullScreenSupport.m

showTabBar, hideTabBar, and moveTabBar all call setToolbarOriginY which is presumably a copy & paste error since they should be calling setTabBarOriginY.

Your code has a bug when add a section view to tableView

Add this code to your viewController

  • (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 50;
    }
  • (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 360, 50)];
    view.backgroundColor = [UIColor redColor];
    return view;
    }
    You will find the bug,I hope you can fix it! thanks
    simulator screen shot apr 12 2016 4 57 59 pm

NJKScrollFullScreen bottom boundary is wrong?

My Problem is: I set contentInset of my scrollView instance and isOverBottomBoundary never become true.

NJKScrollDirection currentScrollDirection = detectScrollDirection(currentOffsetY, _previousOffsetY);
CGFloat topBoundary = -scrollView.contentInset.top;
CGFloat bottomBoundary = scrollView.contentSize.height + scrollView.contentInset.bottom;

Do I need to consider the height of ScrollView?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.