Giter Site home page Giter Site logo

guopf0550 / scsafaripagecontroller Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stefanceriu/scsafaripagecontroller

0.0 2.0 0.0 640 KB

A page view controller component that reproduces Mobile Safari's tab switching behavior

License: MIT License

Ruby 4.48% Objective-C 95.52%

scsafaripagecontroller's Introduction

SCSafariPageController

SCSafariPageController page view controller component that reproduces the behavior seen in Mobile Safari's tab switcher and is intended as a demo for SCPageViewController

Features:

  • can zoom out, partially overlap and lean in pages similar to Safari
  • can zoom in and focus on any of the pages and animates the layout change
  • allows swipe to delete on one or multiple pages at the same time
  • dynamically adapts the inter-item spacings and page angles based on the total number of pages, even while swiping to delete
  • increases the page angles when scrolling outside its bounds
  • supports incremental updates

and all the rest of the SCPageViewController niceties.

Implementation details

SCSafariPageController is built on top of SCPageViewController and makes use of custom page layouters to get the desired effects.

It wraps view controllers inside the scroll view based SCSafariPageWrapperViewController to get the slide to delete feature and then applies variable inter-item spacings and sublayer transforms (angle, perspective and scale) to the pages, based on the total number of pages and the content offset.

Usage

  • Create a new instance and register as its data source and, optionally, delegate
    self.safariPageController = [[SCSafariPageController alloc] init];
	[self.safariPageController setDataSource:self];
	[self.safariPageController setDelegate:self];
  • Implement the SCSafariPageControllerDateSource protocol to define the total number of pages and the view controllers to be used for each of them
- (NSUInteger)numberOfPagesInPageController:(SCSafariPageController *)pageController;

- (UIViewController *)pageController:(SCSafariPageController *)pageController viewControllerForPageAtIndex:(NSUInteger)index;
  • Optionally, listen to any of the following delegate events
- (void)pageController:(SCSafariPageController *)pageController didShowViewController:(UIViewController *)controller atIndex:(NSUInteger)index;

- (void)pageController:(SCSafariPageController *)pageController didHideViewController:(UIViewController *)controller atIndex:(NSUInteger)index;
			  
- (void)pageController:(SCSafariPageController *)pageController didNavigateToOffset:(CGPoint)offset;
   
- (void)pageController:(SCSafariPageController *)pageController didNavigateToPageAtIndex:(NSUInteger)pageIndex;

- (void)pageController:(SCSafariPageController *)pageController willDeletePageAtIndex:(NSUInteger)pageIndex;

- (void)pageController:(SCSafariPageController *)pageController didDeletePageAtIndex:(NSUInteger)pageIndex;
  • Zoom in and out
- (void)zoomOutAnimated:(BOOL)animated completion:(void(^)())completion;

- (void)zoomIntoPageAtIndex:(NSUInteger)index animated:(BOOL)animated completion:(void(^)())completion;
  • SCSafariPageController also supports incremental updates with animations that are customizable through its active layouter
	[self.safariPageController insertPagesAtIndexes:(NSIndexSet *)indexes animated:(BOOL)animated completion:^(void)completion];

	[self.safariPageController deletePagesAtIndexes:(NSIndexSet *)indexes animated:(BOOL)animated completion:^(void)completion]

	[self.safariPageController reloadPagesAtIndexes:(NSIndexSet *)indexes animated:(BOOL)animated completion:^(void)completion]

	[self.safariPageController movePageAtIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex animated:(BOOL)animated completion:^(void)completion]

For more usage examples please have a look at the included demo project (pod try SCSafariPageController)

License

SCSafariPageController is released under the MIT License (MIT) (see the LICENSE file)

Contact

Any suggestions or improvements are more than welcome and I would also love to know if you are using this component in a published application. Feel free to contact me at [email protected] or @stefanceriu.

scsafaripagecontroller's People

Contributors

1ec5 avatar stefanceriu avatar

Watchers

 avatar  avatar

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.