Giter Club home page Giter Club logo

rkswipebetweenviewcontrollers's Introduction

RKSwipeBetweenViewControllers

UIPageViewController and custom UISegmentedControl synchronized and animated. Similar to Spotify's "My Music" section.

Please check the .h to see how to customize anything

Support

Pod

You should not use the pod in most cases, as they don't allow for customizability. I would recommend dragging the .h and .m files manually into your project

pod 'RKSwipeBetweenViewControllers'

Updates, Questions, and Requests

twitter <--- I am a very light twitterer, so I won't spam you

Demo:

(after five minutes of customization)

demo

Any number of any view controllers should technically work, though it doesn't look great with more than 4

Customizable!

Customizable!

(check the RKSwipeBetweenViewControllers.h for actual customizable features)

how to use

(check out the provided AppDelegate to see an example):

Programmatically (preferred)

  1. Import RKSwipeBetweenViewControllers.h

    #import <RKSwipeBetweenViewControllers/RKSwipeBetweenViewControllers.h>
  2. Initialize a UIPageViewController

    UIPageViewController *pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
  3. Initialize a RKSwipeBetweenViewControllers

    RKSwipeBetweenViewControllers *navigationController = [[RKSwipeBetweenViewControllers alloc]initWithRootViewController:pageController];
  4. Add all your ViewControllers (in order) to navigationController.viewControllerArray (try to keep it under 5)

    [navigationController.viewControllerArray addObjectsFromArray:@[viewController1, viewController2, viewController3]];
  5. Use the custom class (or call it as the first controller from app delegate: see below)

    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
    self.window.rootViewController = navigationController;
    [self.window makeKeyAndVisible];

StoryBoard (do not use pods for this one)

  1. Drop the file into your project and import RKSwipeBetweenViewControllers.h

    #import RKSwipeBetweenViewControllers.h
  2. Embed a UIPageViewController inside a UINavigationController. Change the class of the to UINavigationController the custom class (RKSwipeBetweenViewControllers)

  3. change the transition style of the pageviewcontroller to scroll (click on the UIPageViewController in storyboard -> attributes inspector -> transition style -> scroll)

  4. go to the RKSwipeBetweenViewControllers.m file and use it as your own class now. Add your view controllers to "viewControllerArray". See below for various options.

    Programmatically, outside RKSwipeBetweenViewControllers.m (if this navigation bar isn't the first screen that comes up, or if you want to call it from the delegate)

    [customNavController.viewControllerArray addObjectsFromArray:@[viewController1, viewController2, viewController3]];

    Programmatically, inside RKSwipeBetweenViewControllers.m (most cases if your view controllers are programmatically created)

    [viewControllerArray addObjectsFromArray:@[demo,demo2]];

    storyboard, inside RKSwipeBetweenViewControllers.m (if your viewcontrollers are on the storyboard, but make sure to give them storyboard IDs)

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UIViewController* theController = [storyboard instantiateViewControllerWithIdentifier:@"storyboardID"];
    
        [viewControllerArray addObject:theController];

    storyboard, outside RKSwipeBetweenViewControllers.m (if your viewcontrollers are on the storyboard, but make sure to give them storyboard IDs)

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UIViewController* theController = [storyboard instantiateViewControllerWithIdentifier:@"storyboardID"];
    
        [theCustomViewController.viewControllerArray addObject:theController];

Any problems/questions? shoot me a pm

Areas for Improvement / Involvement

  • Working with horizontal layout
  • Working with more than 5 pages
  • Handful of infrequent bugs
  • Better performance when loading pages
  • Changing layout away from UINavigationController to allow the bar to be at the bottom
  • Bug: adding a MKMapView to a UIViewController in storyboard causes strange visual bug. Adding programmatically is fine
  • Crash on load for UITabBarControllers (resolved): #15

rkswipebetweenviewcontrollers's People

Contributors

bryant1410 avatar cwrichardkim avatar jeffreyjackson 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rkswipebetweenviewcontrollers's Issues

How can I hide navigation bar completely?

I'm not able to hide navigation bar even using [self.navigationController setNavigationBarHidden:YES];

I also have commented code which is responsible to draw SegmentButtons.

First Controller Behaviour

Hi Folks,

I am willing to perform a custom action when I swipe left from the first controller.

In that case, there should be no controllers to the left and if that's true, I'd like to recognize it and make a custom action. Is that possible?

Thanks,

Cannot find protocol declaration for nsobject

Hi Richard,
I dragged .h and .m files into my directory and an error said "cannot find protocol declaration for NSObject". I checked that the @protocol RKSwipeBetweenViewControllersDelegate following with a <NSObject>. After deleting that everything was fine.

How to dismiss it

Hi,

I have the following structure:

SignUpViewController ---PRESENT MODAL---> MainViewController

i call RKSwipeBetweenViewControllers inside viewDidLoad() from MainViewController.

  • (void)viewDidLoad {
    [super viewDidLoad];

    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];

    pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
    navigationController = [[RKSwipeBetweenViewControllers alloc]initWithRootViewController:pageController];
    self.scrollViewGeneral = [navigationController getUIScrollView];
    [myManager setMyGeneralVC:self];

    UIStoryboard _storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController_vc1 = [storyboard instantiateViewControllerWithIdentifier:@"myVC1"];
    UIViewController_vc2 = [storyboard instantiateViewControllerWithIdentifier:@"myVC2"];
    UIViewController_vc3 = [storyboard instantiateViewControllerWithIdentifier:@"myVC3"];
    UIViewController*vc4 = [storyboard instantiateViewControllerWithIdentifier:@"myVC4"];

    [navigationController.viewControllerArray addObjectsFromArray:@[vc1, vc2, vc3,vc4]];

    self.window.rootViewController = navigationController;
    [self.window makeKeyAndVisible];
    }

It works fine.
I created a button "disconnect" to come back to SignUpViewController.
I must dismiss ViewControllers (myVC1, myVC2, myVC3, myVC4) and also the MainViewController.

i tried this from MainViewController:

-(void)dismissView
{
UIStoryboard _storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController_vc1 = [storyboard instantiateViewControllerWithIdentifier:@"myVC1"];
UIViewController_vc2 = [storyboard instantiateViewControllerWithIdentifier:@"myVC2"];
UIViewController_vc3 = [storyboard instantiateViewControllerWithIdentifier:@"myVC3"];
UIViewController*vc4 = [storyboard instantiateViewControllerWithIdentifier:@"myVC4"];

//FIRST TRY
[vc1.navigationController popViewControllerAnimated:NO];
[vc2.navigationController popViewControllerAnimated:NO];
[vc3.navigationController popViewControllerAnimated:NO];
[vc4.navigationController popViewControllerAnimated:NO];

//SECOND TRY
[vc1.navigationController dismissViewControllerAnimated:NO completion:nil];
[vc2.navigationController dismissViewControllerAnimated:NO completion:nil];
[vc3.navigationController dismissViewControllerAnimated:NO completion:nil];
[vc4.navigationController dismissViewControllerAnimated:NO completion:nil];
[self.navigationController dismissViewControllerAnimated:NO completion:nil];

//THIRD TRY

[vc1.navigationController popToRootViewControllerAnimated:NO];
[vc2.navigationController popToRootViewControllerAnimated:NO];
[vc3.navigationController popToRootViewControllerAnimated:NO];
[vc4.navigationController popToRootViewControllerAnimated:NO];
[self.navigationController popToRootViewControllerAnimated:NO];

}

It's not works.
thanks for help ;)

the project has some crashes

  1. terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Duplicate states in queue
    when i click quickly Not adjacent button,it will happen.
    2.Removing a view controller from UIPageViewController
    when i swiping viewController and i click viewController'view'subviews at the same time,it will happen

Created a version that behaves more like Tinder in Swift

Hey @cwRichardKim

Thanks for creating and sharing this!!!

I was able to port it into Swift with behavior that is more like Tinder located at:

https://github.com/jonathanxie/JXSwipeBetweenViews/blob/master/README.md

Might be a bit buggy but it works decently well...

swipe

Also, for the X_OFFSET issue, I noticed that it appears if you set the navigationView to the titleView of the navigationBar:

pageController.navigationController.navigationBar.topItem.titleView = navigationView;

Try setting the background color of the navigationBar to red and you can see that it's somehow smaller than the screen even though the self.navigationBar.frame.size.width is the same as the width of the screen.

Anyway, I set my navigationView to be a subview of the navigationBar and I didn't have the X_OFFSET issue. The X_OFFSET issue gets really annoying when I run the app on different devices on fullscreen mode instead of scalemode. Couldn't figure out an easy solution so I just did this:

 navigationBar.addSubview(navigationView)

I have a version of this in Objective-C using your code base. If you want me to put that up too for others who are still using Objective-C, let me know!

Hope this helps others out!

Putting this into one UIViewController

Is there any way this can be done just in a UIViewController or a page controller? I am not a fan of all this happening in the navigation controller because, if I were to segue some where and then tap on another tab in my tabbar and then return to the tab with this SwipeBetweenViewControllers, there are methods being called that should NOT be called since I am on another view controller in the navigation stack array(such as the delegate method). I understand why it is happening because there is a custom class for the navigation controller in the embedded navigation controller in the storyboard. Maybe I am making this entirely wrong. But if there is an example I am trying to copy, it is Instagram's News Feed. Looks identical to the custom library you have here. The swipe with the almost identical segmented control.

viewWillAppear causes controller to initialize again

The setup code inside viewWillAppear should only be performed once. Inside my app it happens that I push a view controller and when navigating back viewWillAppear is called again. This then causes all the pages to be setup again and the current index is reset.

I want to put 'tab bar' below sub ViewController

your Tab bar is 'in' the navigation bar.

But I want to put it bottom at the sub viewcontroller...

Is it possible?

I'm grateful your project for nice performance swiping between viewcontrollers but 'RKSwipeBetweenViewControllers' is the subclass of NavigationController, not the UIViewController... That's my sorry point...

Can I put it there? Please help me

ViewControllers don't maintain state on modal dismissal

When I dismiss a modal within one of my view controllers, the swipe controller somehow resets back to the first view controller in the array. I've tried to set it back to the right view controller in the completion block of the modal dismissal, but that didn't work. Any ideas?

Diagonal Dragging

I noticed when I move this view controller it drags in a multitude of directions besides up and down and I am assuming that is because of scrollview? Is there any way to stop it from moving diagonally? I am currently trying to stop the scrollview from moving in diagonal directions with every snippet of code I can find online. Could it be because I have auto layout turned on?

Change button colors on click

How to change the button color when it is clicked in order know that this is is selected tab and the other buttons should have old unselected color.

how can i push the RKSwipeBetweenViewControllers in a uinavigationviewcontroller

when i push the object of RKSwipeBetweenViewControllers
it crash.
code:
RKSwipeBetweenViewControllers *swipeVC = [RKSwipeBetweenViewControllers newSwipeBetweenViewControllers];
[nav_tweet.viewControllerArray addObjectsFromArray:@[[TimelineViewController newTimelineViewControllerWithType:TimelineViewControllerType_Nearby],
[TimelineViewController newTimelineViewControllerWithType:TimelineViewControllerType_Hot]]];
nav_tweet.buttonText = @[@"A", @"B"];
[self.navigationController pushViewController:nav_tweet animated:YES];

then it crash log is : NSScanner: nil string argument
how to fix it ?

i want to add a back button on the nav Bar

Hi Sir,

First of all this is amazing and its easy to use, Thanks.

I would like to know how do i add a back button, because doing the same on the storyboard moves the name of the controllers to the right where i want to show the cancel or back button.

Also when i try to change the height of navBar to show my cancel button, the buttons are moved more upwards.
So now the changes has to be done in :

UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(X_BUFFER+i*(self.view.frame.size.width-2*X_BUFFER)/numControllers-X_OFFSET, Y_BUFFER, (self.view.frame.size.width-2*X_BUFFER)/numControllers, HEIGHT)];

 [navigationView addSubview:button];

Is there any other way around.

Thanks in Advance.

How can I move the tab to bottom?

I found you use navigationBar . So the Tab button will put top at screen.
But I want to move the tab to the bottom. Can I move the navigation bar to bottom?
If I move the navigation bar to the bottom at screen, the Apple will reject the app?
Thank you.

Unbalanced calls to begin/end appearance transitions for ...

So far, loving the implementation @cwRichardKim (plus checked out your other projects too and excited to try those out). Thanks for putting this together. How long did it take you?

I'm noticing

Unbalanced calls to begin/end appearance transitions

for in the console when I dismiss a viewcontroller that was presented via

    [self presentViewController:destinationVC
                       animated:YES
                     completion:nil];

Any help on this one?

Customization

The fact that you have to modify the implementation is completely ridiculous, because that negates all the advantages of using source control. If you push a change to git, there is no way for us to receive the update without manually adding it in ourselves in our heavily modified implementations. It would be much better if all of the private customization properties were exposed in the implementation so customization could be done from another class.

I appreciate your work here, but I think this library would be much better off if these changes were made.

Wrong highlighter position when swiping beyond the view's center position.

I admit it's hard to tell what's going on by reading the title of this issue but I didn't know how to put it in a better way and I think it's severe.

To reproduce

  • use only 2 view controllers in UIPageVIewController (that's the scenario I use).
  • swipe to the second view controller and continue swiping but keep your fingers down on the display so that the highlight bar'x origin x position will continue to be larger than the center of the screen (in case of e.g. iPhone8 = 187.5).
  • In order to reproduce it, it's important that you do not lift your finger after you started scrolling from the first to the second vc. If that's hard to do, keep pushing your first finger down on the display and use a second finger to scroll further.
  • Once the highlight bar's x position is > 187.5 (in case of the iPhone 8) it will switch back to 0 and the highlight bar is in the position of the first view controller even thought the second vc is currently displayed.

@cwRichardKim any idea how to fix that?

Method 'syncScrollView'

the method 'syncScrollView' has this code below:
for (UIView* view in pageController.view.subviews){
if([view isKindOfClass:[UIScrollView class]])
{
pageScrollView = (UIScrollView *)view;
pageScrollView.delegate = self;
}
}

What I can not undestand is that how there is the view whose class is 'UIScrollView'
Programmer set pageController's viewcontrollers so there might not be a uiscrollview.
But it always pass that code 'if([view isKindOfClass:[UIScrollView class]])'
I don't understand

Add Child View Controllers

I'm trying to combine RKSBVC with a modal transition using UIViewControllerTransitioningDelegate. I want to access the cell they clicked on in the first page, but just instantiating the view controllers in appDelegate doesn't seem to setup a Parent-Child relationship.

Is there another way to init the slider so that it creates the right relationship with its Child Controllers?

how add this RKswipeBetweenVC

i'm trying to add RKSwipeBetweenViewControllers after click on table cell . but i m unable to do it pls provide me solution .

Height Of view controller

Hey man, first, awesome job!
Second, I'm new to Xcode so please bear with me :-).

When I run you test it shows the app running in the middle of the screen with about a cm on the top and bottom (iphone6) of empty space - if I remember correctly there is a way to autosize - (self.view.frame.size.width/height) how would I implement that ?

Adding RKSwipeBetweenViewControllers to UITabBarController crashed.

I have 4 UIViewController organized by UITabBarController,
When I add RKSwipeBetweenViewControllers to the fourth tab controller, as soon as I click the 4th tab, the amount of controllers of UITabBarController become 3. The tab controller(RKSwipeBetweenViewControllers) is gone~

When I click the 4th one, it crashed~

Swift Demo

Is it possible if I send a pull request for swift demo project?

Black bar at status bar if navigationBar is hidden

I'm hiding the segmentbuttons by putting in

pageController.navigationController.navigationBar.hidden = YES;

in the viewWillAppear in RKSwipeBetweenViewControllers.m. It mostly works fine, except when the app is first launched, there is a black bar where the status bar normally is. If I touch anywhere on the screen, the view slides up and everything works fine afterwards.
blackbar

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.