Giter Site home page Giter Site logo

mgswipetabbarcontroller's Introduction

MGSwipeTabBarController

Example Screenshots

ScreenShot 1

Demo

Check out the demo project. Follow the steps below and make sure cocoapods is installed.

$ git clone https://github.com/mglagola/MGSwipeTabBarController.git
$ cd MGSwipeTabBarController/Demo
$ pod install
$ open Demo.xcworkspace/

Setup

CocoaPods is recommended.

CocoaPods

  • Add pod 'MGSwipeTabBarController', '~>X.X' in your Podfile. Fill in ~>X.X with the latest pod spec version or :head if you live dangerously.
  • #import <MGSwipeTabBarController/MGSwipeTabBarController.h>

Old Style

  • Drag and drop the MGSwipeTabBarController/MGSwipeTabBarController Folder into your iOS project
  • #import "MGSwipeTabBarController.h"

Example Usage

Create a MGSwipeTabBarController

Option 1 - Init

NSArray *viewControllers = . . . //your view controllers
MGSwipeTabBarController *swipeController = [[MGSwipeTabBarController alloc] initWithViewControllers:viewControllers]; 

Option 2 - Setter

NSArray *viewControllers = . . . //your view controllers
MGSwipeTabBarController *swipeController = . . . // initialized some way (i.e. storyboard, nib, etc).
swipeController.viewControllers = viewControllers;

Documentation

@protocol MGSwipeTabBarControllerDelegate <NSObject>
@optional

/*
 This method will be called prior to the start of the scroll animation.
 
 NOTE: there is no bounds checking for this method. 
 So if the user attempts to scroll out of bounds, lets say from index 0 to off screen left, 
 then @toIndex = -1 and @fromIndex = 0.
 This can be used to your advantage, see the Demo project.
*/
- (void) swipeTabBarController:(MGSwipeTabBarController*)swipeTabBarController
             willScrollToIndex:(NSInteger)toIndex
                     fromIndex:(NSInteger)fromIndex;

/*
 This method will be called after the scroll animation completes.
 There is bounds checking here, unlike swipeTabBarController:willScrollToIndex:fromIndex:
*/
- (void) swipeTabBarController:(MGSwipeTabBarController*)swipeTabBarController
              didScrollToIndex:(NSInteger)toIndex
                     fromIndex:(NSInteger)fromIndex;


- (void) swipeTabBarController:(MGSwipeTabBarController*)swipeTabBarController
                       panning:(CGFloat)pan;

@end

@interface MGSwipeTabBarController : UIViewController <UIGestureRecognizerDelegate>

extern CGFloat const kBPDefaultSelectedIndexAnimationDuration;

//The current view controller stack.
@property (nonatomic, strong) NSArray *viewControllers;

/*
 The current selected index of the controller stack
 Setting this property will also change the value of the 'selectedViewController'
 property accordingly.
 
 This cannot be set over the bounds of the viewController stack
 
 This also cannot be set directly.  Use the setters:
 setSelectedIndex:animated: and
 setSelectedIndex:animationDuration:completion:
*/
@property (nonatomic, readonly) NSInteger selectedIndex;

//Contains the value of the currently selected view controller of the controller stack
@property (nonatomic, weak, readonly) UIViewController *selectedViewController;

@property (nonatomic) id<MGSwipeTabBarControllerDelegate> delegate;

/*
 Default is 0.5 (in seconds)
 Value cannot be less than 0
 
 Responsible for detecting swipes. Swipes are determinded 
 via the swipeInterval. if the pan gesture ended within 
 0 and the swipeInterval, a swipe has been detected and 
 will animate to the new tab.
 */
@property (nonatomic) NSTimeInterval swipeInterval;

@property (nonatomic, readonly) UIView *containerView;

- (id) initWithViewControllers:(NSArray*)viewControllers;

- (void) setSelectedIndex:(NSInteger)selectedIndex animated:(BOOL)animated;
- (void) setSelectedIndex:(NSInteger)selectedIndex animationDuration:(CGFloat)animationDuration completion:(void(^)(BOOL finished))completion;

@end

Limitations

There is a bug currently with transparent UI bars. The demo demonstrates this bug. When I would seem to fix this issue for iOS 7, it would not work on iOS 8 and vice versa. The issue can be found here

mgswipetabbarcontroller's People

Contributors

mglagola avatar stefreak 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.