Convert Figma logo to code with AI

cwRichardKim logoRKSwipeBetweenViewControllers

Swipe between ViewControllers like in the Spotify or Twitter app with an interactive Segmented Control in the Navigation Bar

1,679
156
1,679
19

Top Related Projects

24,358

Reactive Programming in Swift

Cocoa framework and Obj-C dynamism bindings for ReactiveSwift.

:octocat: 📃 FoldingCell is an expanding content cell with animation made by @Ramotion

:octocat: RAMAnimatedTabBarController is a Swift UI module library for adding animation to iOS tabbar items and icons. iOS library made by @Ramotion

Animated side menu with customizable UI

Quick Overview

RKSwipeBetweenViewControllers is an iOS library that provides a custom UIViewController container for easy implementation of a swipeable top menu. It allows users to navigate between view controllers using swipe gestures or by tapping on menu items, similar to the interface seen in apps like Twitter or Spotify.

Pros

  • Easy to implement and customize
  • Smooth animations and transitions between view controllers
  • Supports both swipe gestures and tap navigation
  • Compatible with Storyboard and programmatic UI setup

Cons

  • Last updated in 2017, potentially outdated for newer iOS versions
  • Limited documentation and examples
  • May require additional work to integrate with modern iOS app architectures
  • No built-in support for dynamic menu items

Code Examples

  1. Setting up the RKSwipeBetweenViewControllers:
let navigationController = UINavigationController(rootViewController: RKSwipeBetweenViewControllers())
self.window?.rootViewController = navigationController
  1. Adding view controllers to the container:
let swipeController = RKSwipeBetweenViewControllers()
swipeController.viewControllerArray = [
    UIViewController(),
    UIViewController(),
    UIViewController()
]
  1. Customizing the appearance:
swipeController.buttonText = ["First", "Second", "Third"]
swipeController.selectionBar.backgroundColor = .blue
swipeController.selectionBar.height = 3

Getting Started

  1. Add the RKSwipeBetweenViewControllers folder to your Xcode project.
  2. Import the library in your AppDelegate or ViewController:
import RKSwipeBetweenViewControllers
  1. Create an instance of RKSwipeBetweenViewControllers and set it as the root view controller:
let swipeController = RKSwipeBetweenViewControllers()
swipeController.viewControllerArray = [
    FirstViewController(),
    SecondViewController(),
    ThirdViewController()
]
swipeController.buttonText = ["First", "Second", "Third"]

let navigationController = UINavigationController(rootViewController: swipeController)
self.window?.rootViewController = navigationController
  1. Customize the appearance and behavior as needed using the available properties and methods.

Competitor Comparisons

24,358

Reactive Programming in Swift

Pros of RxSwift

  • Comprehensive reactive programming framework for Swift
  • Supports complex asynchronous operations and data streams
  • Large community and extensive documentation

Cons of RxSwift

  • Steeper learning curve for developers new to reactive programming
  • Can be overkill for simpler UI interactions
  • Potential performance overhead for basic operations

Code Comparison

RxSwift:

Observable.from([1, 2, 3, 4, 5])
    .filter { $0 % 2 == 0 }
    .map { $0 * 2 }
    .subscribe(onNext: { print($0) })

RKSwipeBetweenViewControllers:

let swipeController = RKSwipeBetweenViewControllers()
swipeController.viewControllerArray = [vc1, vc2, vc3]
self.window?.rootViewController = swipeController

Summary

RxSwift is a powerful reactive programming framework that excels in handling complex asynchronous operations and data streams. It offers a comprehensive solution for reactive programming in Swift, backed by a large community and extensive documentation. However, it comes with a steeper learning curve and may be excessive for simpler UI interactions.

RKSwipeBetweenViewControllers, on the other hand, is a more focused library specifically designed for creating swipeable view controllers. It provides a simpler implementation for this specific use case, making it easier to set up and use for developers who only need this functionality.

The choice between these libraries depends on the project's requirements. RxSwift is better suited for complex, data-driven applications, while RKSwipeBetweenViewControllers is ideal for projects that primarily need a swipeable interface between view controllers.

Cocoa framework and Obj-C dynamism bindings for ReactiveSwift.

Pros of ReactiveCocoa

  • Provides a comprehensive framework for reactive programming in iOS and macOS
  • Offers powerful abstractions for handling asynchronous events and data streams
  • Supports functional reactive programming paradigms, enabling more declarative code

Cons of ReactiveCocoa

  • Steeper learning curve due to its complex concepts and abstractions
  • May introduce unnecessary complexity for simpler UI interactions
  • Requires a significant shift in programming paradigm for developers new to reactive programming

Code Comparison

ReactiveCocoa:

let searchResults = searchString
    .throttle(0.3, on: QueueScheduler.main)
    .flatMap(.latest) { (query: String) -> SignalProducer<[SearchResult], NoError> in
        return API.search(query)
    }

RKSwipeBetweenViewControllers:

[self.navigationController.view addSubview:self.pageController.view];
[self.navigationController.view addSubview:self.buttonBarView];
[self addChildViewController:self.pageController];
[self.pageController didMoveToParentViewController:self];

ReactiveCocoa focuses on reactive programming patterns, while RKSwipeBetweenViewControllers provides a simpler, more direct approach to implementing swipeable view controllers. ReactiveCocoa's code demonstrates handling of asynchronous events, while RKSwipeBetweenViewControllers' code shows straightforward view and controller management.

:octocat: 📃 FoldingCell is an expanding content cell with animation made by @Ramotion

Pros of folding-cell

  • More visually appealing and interactive UI element
  • Supports both Swift and Objective-C
  • Highly customizable with various animation options

Cons of folding-cell

  • Limited to a specific UI pattern (folding cell)
  • May require more setup and configuration

Code Comparison

folding-cell:

let cell = FoldingCell()
cell.itemCount = 4
cell.backViewColor = .blue
cell.foregroundView = customView
cell.unfold(animated: true)

RKSwipeBetweenViewControllers:

RKSwipeBetweenViewControllers *navigationController = [[RKSwipeBetweenViewControllers alloc] initWithNibName:nil bundle:nil];
[navigationController.viewControllerArray addObjectsFromArray:@[viewController1, viewController2, viewController3]];
[self presentViewController:navigationController animated:YES completion:nil];

Summary

folding-cell offers a unique and visually appealing UI element with high customization options, supporting both Swift and Objective-C. However, it's limited to a specific UI pattern and may require more setup.

RKSwipeBetweenViewControllers provides a simpler implementation for swipeable view controllers, but lacks the visual flair and customization options of folding-cell.

The code comparison shows that folding-cell focuses on cell configuration, while RKSwipeBetweenViewControllers emphasizes navigation controller setup with multiple view controllers.

:octocat: RAMAnimatedTabBarController is a Swift UI module library for adding animation to iOS tabbar items and icons. iOS library made by @Ramotion

Pros of animated-tab-bar

  • More visually appealing with animated icons and customizable designs
  • Supports both Swift and Objective-C
  • Actively maintained with recent updates and a larger community

Cons of animated-tab-bar

  • More complex implementation due to additional animation features
  • Potentially higher resource usage due to animations
  • Limited to tab bar functionality, less flexible for other navigation patterns

Code Comparison

RKSwipeBetweenViewControllers:

let navigationController = UINavigationController(rootViewController: RKSwipeBetweenViewControllers(viewControllers: [vc1, vc2, vc3]))

animated-tab-bar:

let tabBarController = RAMAnimatedTabBarController()
tabBarController.viewControllers = [vc1, vc2, vc3]
tabBarController.animationTabBarHidden = false

Summary

RKSwipeBetweenViewControllers offers a simpler implementation for swipe-based navigation between view controllers, while animated-tab-bar focuses on providing visually appealing animated tab bars. The choice between the two depends on the specific navigation requirements and desired visual effects in your iOS application.

Animated side menu with customizable UI

Pros of Side-Menu.iOS

  • More visually appealing and customizable animation effects
  • Supports both left and right side menus
  • Actively maintained with recent updates

Cons of Side-Menu.iOS

  • More complex implementation compared to RKSwipeBetweenViewControllers
  • Requires more setup and configuration
  • Limited to side menu functionality, while RKSwipeBetweenViewControllers offers swipe-based navigation

Code Comparison

Side-Menu.iOS:

let menuLeftNavigationController = UISideMenuNavigationController(rootViewController: YourViewController)
SideMenuManager.default.leftMenuNavigationController = menuLeftNavigationController
SideMenuManager.default.addPanGestureToPresent(toView: self.navigationController!.navigationBar)
SideMenuManager.default.addScreenEdgePanGesturesToPresent(toView: self.navigationController!.view)

RKSwipeBetweenViewControllers:

let nav = RKSwipeBetweenViewControllers()
nav.viewControllerArray = [vc1, vc2, vc3]
nav.setNavigationBarHidden(true, animated: false)
self.window?.rootViewController = nav

Side-Menu.iOS offers a more feature-rich side menu implementation with customizable animations, while RKSwipeBetweenViewControllers provides a simpler swipe-based navigation between view controllers. The code comparison shows that Side-Menu.iOS requires more setup, but offers greater flexibility in terms of menu positioning and gesture recognition. RKSwipeBetweenViewControllers has a more straightforward implementation, making it easier to set up for basic swipe navigation between views.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

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): https://github.com/cwRichardKim/RKSwipeBetweenViewControllers/pull/15