Convert Figma logo to code with AI

modocache logoMDCSwipeToChoose

Swipe to "like" or "dislike" any view, just like Tinder.app. Build a flashcard app, a photo viewer, and more, in minutes, not hours!

2,552
422
2,552
50

Top Related Projects

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

Custom transition between viewcontrollers holding tableviews

Animated side menu with customizable UI

Folding Tab Bar and Tab Bar Controller

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

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

Quick Overview

MDCSwipeToChoose is an iOS library that implements a UI control similar to Tinder's swipe-to-like gesture. It allows users to swipe left or right on views to indicate a choice, providing a smooth and intuitive interaction for binary decision-making in iOS applications.

Pros

  • Easy to integrate into existing iOS projects
  • Customizable appearance and behavior
  • Supports both programmatic and Interface Builder implementation
  • Includes a demo app for quick understanding and testing

Cons

  • Limited to iOS platform only
  • Last updated in 2015, potentially outdated for newer iOS versions
  • Lacks advanced features like undo or multi-choice options
  • May require additional work to adapt to modern iOS development practices

Code Examples

  1. Basic setup of a swipeable view:
let options = MDCSwipeToChooseViewOptions()
options.likedText = "Keep"
options.likedColor = .green
options.nopeText = "Delete"
options.nopeColor = .red

let swipeView = MDCSwipeToChooseView(frame: view.bounds, options: options)
swipeView.imageView.image = UIImage(named: "photo")
view.addSubview(swipeView)
  1. Handling swipe results:
swipeView.didBeginSwipingHandler = { view, direction in
    print("Began swiping \(direction)")
}

swipeView.didEndSwipingHandler = { view, direction in
    if direction == .Right {
        print("Photo kept")
    } else if direction == .Left {
        print("Photo deleted")
    }
}
  1. Programmatically triggering a swipe:
MDCSwipeToChooseView.swipeView(swipeView, 
                               inDirection: .Left, 
                               programmatically: true)

Getting Started

  1. Add MDCSwipeToChoose to your project using CocoaPods:
pod 'MDCSwipeToChoose'
  1. Import the library in your Swift file:
import MDCSwipeToChoose
  1. Create and configure a swipeable view:
let options = MDCSwipeToChooseViewOptions()
options.likedText = "Yes"
options.nopeText = "No"

let swipeView = MDCSwipeToChooseView(frame: CGRect(x: 0, y: 0, width: 300, height: 300), options: options)
swipeView.imageView.image = UIImage(named: "example")
view.addSubview(swipeView)

swipeView.didEndSwipingHandler = { view, direction in
    print("Swiped \(direction)")
}

Competitor Comparisons

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

Pros of RKSwipeBetweenViewControllers

  • Offers a more comprehensive solution for navigating between multiple view controllers
  • Provides built-in support for a custom tab bar with icons
  • Includes features like infinite scrolling and dynamic page loading

Cons of RKSwipeBetweenViewControllers

  • Less focused on the specific swipe-to-choose functionality
  • May be more complex to implement for simpler use cases
  • Last updated in 2017, potentially outdated for newer iOS versions

Code Comparison

MDCSwipeToChoose:

let options = MDCSwipeToChooseViewOptions()
options.delegate = self
let swipeToChooseView = MDCSwipeToChooseView(frame: frame, options: options)
view.addSubview(swipeToChooseView)

RKSwipeBetweenViewControllers:

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

MDCSwipeToChoose focuses on providing a simple swipe-to-choose interface, ideal for Tinder-like applications. It offers a lightweight solution with customizable options for swipe gestures and animations.

RKSwipeBetweenViewControllers, on the other hand, provides a more comprehensive solution for navigating between multiple view controllers with swipe gestures. It includes additional features like a custom tab bar and infinite scrolling, making it suitable for more complex applications with multiple screens.

While MDCSwipeToChoose is more specialized and easier to implement for specific swipe-to-choose functionality, RKSwipeBetweenViewControllers offers greater flexibility for building multi-screen applications with swipe navigation.

Custom transition between viewcontrollers holding tableviews

Pros of AMWaveTransition

  • Offers a unique wave-like transition effect for view controllers
  • Provides customizable animation parameters for fine-tuning the transition
  • Supports both push and pop transitions

Cons of AMWaveTransition

  • Limited to a specific transition style, less versatile than MDCSwipeToChoose
  • May require more setup and configuration for basic usage
  • Potentially more resource-intensive due to complex animations

Code Comparison

AMWaveTransition:

let transition = AMWaveTransition()
navigationController?.delegate = transition
navigationController?.pushViewController(viewController, animated: true)

MDCSwipeToChoose:

MDCSwipeToChooseView *swipeView = [[MDCSwipeToChooseView alloc] initWithFrame:frame
                                                                      options:options];
[self.view addSubview:swipeView];

AMWaveTransition focuses on creating a wave-like transition between view controllers, while MDCSwipeToChoose is designed for implementing swipe-based choice interfaces. AMWaveTransition requires setting up a transition delegate, whereas MDCSwipeToChoose involves creating and configuring a swipe view. The code snippets demonstrate the primary setup for each library, highlighting their different purposes and implementation approaches.

Animated side menu with customizable UI

Pros of Side-Menu.iOS

  • Offers a visually appealing and customizable side menu animation
  • Provides a complete solution for implementing a side menu in iOS apps
  • Includes sample code and a demo project for easy integration

Cons of Side-Menu.iOS

  • Limited to side menu functionality, less versatile than MDCSwipeToChoose
  • May require more setup and configuration for basic menu implementations
  • Potentially higher learning curve for developers new to custom UI animations

Code Comparison

Side-Menu.iOS:

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

MDCSwipeToChoose:

MDCSwipeToChooseView *view = [[MDCSwipeToChooseView alloc] initWithFrame:self.view.bounds
                                                                  options:options];
view.delegate = self;
[self.view addSubview:view];

Summary

Side-Menu.iOS focuses on providing a polished side menu solution with smooth animations, while MDCSwipeToChoose offers a more versatile swipe-based interaction system. Side-Menu.iOS may be better suited for projects specifically requiring an animated side menu, whereas MDCSwipeToChoose could be more appropriate for apps needing swipe-based decision-making interfaces. The code comparison shows that Side-Menu.iOS requires more setup for its specific functionality, while MDCSwipeToChoose offers a simpler implementation for its core features.

Folding Tab Bar and Tab Bar Controller

Pros of FoldingTabBar.iOS

  • Offers a unique and visually appealing folding animation for tab bars
  • Provides a customizable and interactive user interface element
  • Supports both portrait and landscape orientations

Cons of FoldingTabBar.iOS

  • Limited to tab bar functionality, less versatile than MDCSwipeToChoose
  • May require more setup and customization to integrate into existing projects
  • Potentially more resource-intensive due to complex animations

Code Comparison

FoldingTabBar.iOS:

let tabBarController = YALFoldingTabBarController()
tabBarController.viewControllers = [firstViewController, secondViewController]
tabBarController.leftBarItems = [firstItem, secondItem]
tabBarController.rightBarItems = [thirdItem, fourthItem]

MDCSwipeToChoose:

MDCSwipeOptions *options = [MDCSwipeOptions new];
options.delegate = self;
options.likedText = @"Keep";
options.likedColor = [UIColor blueColor];
options.nopeText = @"Delete";
options.nopeColor = [UIColor redColor];

FoldingTabBar.iOS focuses on creating an animated tab bar with a unique folding effect, while MDCSwipeToChoose provides a more general-purpose swipe-to-choose interface. The code examples show that FoldingTabBar.iOS requires setting up view controllers and bar items, whereas MDCSwipeToChoose involves configuring swipe options and customizing the appearance of choice indicators.

: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

  • Offers visually appealing animations for tab bar items
  • Supports customization of icons, colors, and animation types
  • Provides a more engaging user experience for navigation

Cons of animated-tab-bar

  • Limited to tab bar functionality, less versatile than MDCSwipeToChoose
  • May require more setup and configuration for complex animations
  • Potentially higher performance overhead due to animations

Code Comparison

MDCSwipeToChoose:

let options = MDCSwipeToChooseViewOptions()
options.delegate = self
options.likedText = "Keep"
options.likedColor = UIColor.green
let swipeToChooseView = MDCSwipeToChooseView(frame: frame, options: options)

animated-tab-bar:

let tabBar = RAMAnimatedTabBarController()
let item1 = RAMAnimatedTabBarItem(title: "Home", image: UIImage(named: "home"), tag: 1)
item1.animation = RAMBounceAnimation()
tabBar.viewControllers = [homeVC]
tabBar.animatedItems = [item1]

Both libraries offer easy-to-use APIs for their respective functionalities. MDCSwipeToChoose focuses on swipe gestures for decision-making interfaces, while animated-tab-bar specializes in enhancing tab bar appearances with animations. The choice between the two depends on the specific requirements of your app's user interface and navigation structure.

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

Pros of folding-cell

  • More visually appealing and interactive UI element
  • Supports custom content for both folded and unfolded states
  • Offers smooth animations and transitions

Cons of folding-cell

  • More complex implementation and setup
  • Limited to specific use cases (expanding cells)
  • Potentially higher performance overhead due to animations

Code Comparison

MDCSwipeToChoose:

let options = MDCSwipeToChooseViewOptions()
options.delegate = self
let swipeView = MDCSwipeToChooseView(frame: frame, options: options)
view.addSubview(swipeView)

folding-cell:

let cell = FoldingCell()
cell.delegate = self
cell.itemCount = 2
cell.setup(name: "Cell Title", duration: 0.5, backViewColor: .blue)
tableView.register(FoldingCell.self, forCellReuseIdentifier: "cell")

While MDCSwipeToChoose focuses on swipe gestures for selection, folding-cell provides an expandable cell with custom content. MDCSwipeToChoose is simpler to implement but offers less visual flair. folding-cell provides a more engaging user experience at the cost of increased complexity and potential performance impact.

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

MDCSwipeToChoose

Build Status

Swipe to "like" or "dislike" any view, just like Tinder.app. Build a flashcard app, a photo viewer, and more, in minutes, not hours!

  • Use UIView+MDCSwipeToChoose to add a swipe gesture and callbacks to any UIView.
  • Use MDCSwipeToChooseView to get a UI nearly identical to Tinder.app in just a few lines of code.

You may view slides on some the architecture decisions that went into this library here.

How to Install via CocoaPods

Place the following in your Podfile and run pod install:

pod "MDCSwipeToChoose"

How to Use

Check out the sample app for an example of how to use MDCSwipeToChooseView to build the UI in the GIF above.

NOTE: You must run pod install in the Examples/LikedOrNope directory before building the example app.

Every public class contains documentation in its header file.

Swiping Yes/No

The following is an example of how you can use MDCSwipeToChooseView to display a photo. The user can choose to delete it by swiping left, or save it by swiping right.

Objective-C

#import <MDCSwipeToChoose/MDCSwipeToChoose.h>

// ... in a view controller

#pragma mark - Creating and Customizing a MDCSwipeToChooseView

- (void)viewDidLoad {
    [super viewDidLoad];

    // You can customize MDCSwipeToChooseView using MDCSwipeToChooseViewOptions.
    MDCSwipeToChooseViewOptions *options = [MDCSwipeToChooseViewOptions new];
    options.likedText = @"Keep";
    options.likedColor = [UIColor blueColor];
    options.nopeText = @"Delete";
    options.onPan = ^(MDCPanState *state){
        if (state.thresholdRatio == 1.f && state.direction == MDCSwipeDirectionLeft) {
            NSLog(@"Let go now to delete the photo!");
        }
    };

    MDCSwipeToChooseView *view = [[MDCSwipeToChooseView alloc] initWithFrame:self.view.bounds
                                                                     options:options];
    view.imageView.image = [UIImage imageNamed:@"photo"];
    [self.view addSubview:view];
}

#pragma mark - MDCSwipeToChooseDelegate Callbacks

// This is called when a user didn't fully swipe left or right.
- (void)viewDidCancelSwipe:(UIView *)view {
    NSLog(@"Couldn't decide, huh?");
}

// Sent before a choice is made. Cancel the choice by returning `NO`. Otherwise return `YES`.
- (BOOL)view:(UIView *)view shouldBeChosenWithDirection:(MDCSwipeDirection)direction {
    if (direction == MDCSwipeDirectionLeft) {
        return YES;
    } else {
        // Snap the view back and cancel the choice.
        [UIView animateWithDuration:0.16 animations:^{
            view.transform = CGAffineTransformIdentity;
            view.center = [view superview].center;
        }];
        return NO;
    }
}

// This is called then a user swipes the view fully left or right.
- (void)view:(UIView *)view wasChosenWithDirection:(MDCSwipeDirection)direction {
    if (direction == MDCSwipeDirectionLeft) {
        NSLog(@"Photo deleted!");
    } else {
        NSLog(@"Photo saved!");
    }
}

Swift

To use objective-c code from swift, you need to use bridging-header.

#ifndef BridgingHeader_h
#define BridgingHeader_h

#import <UIKit/UIKit.h>
#import <MDCSwipeToChoose/MDCSwipeToChoose.h>

#endif

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

		let options = MDCSwipeToChooseViewOptions()
		options.delegate = self
		options.likedText = "Keep"
		options.likedColor = UIColor.blue
		options.nopeText = "Delete"
		options.nopeColor = UIColor.red
		options.onPan = { state -> Void in
			if state?.thresholdRatio == 1 && state?.direction == .left {
				print("Photo deleted!")
			}
		}

		let view = MDCSwipeToChooseView(frame: self.view.bounds, options: options)
		view?.imageView.image = UIImage(named: "photo.png")
		self.view.addSubview(view!)
	}

}

extension ViewController: MDCSwipeToChooseDelegate {

	// This is called when a user didn't fully swipe left or right.
	func viewDidCancelSwipe(_ view: UIView) -> Void{
		print("Couldn't decide, huh?")
	}

	// Sent before a choice is made. Cancel the choice by returning `false`. Otherwise return `true`.
	func view(_ view: UIView, shouldBeChosenWith: MDCSwipeDirection) -> Bool {
		if shouldBeChosenWith == .left {
			return true
		} else {
			// Snap the view back and cancel the choice.
			UIView.animate(withDuration: 0.16, animations: { () -> Void in
				view.transform = CGAffineTransform.identity
				view.center = view.superview!.center
			})
			return false
		}
	}

	// This is called when a user swipes the view fully left or right.
	func view(_ view: UIView, wasChosenWith: MDCSwipeDirection) -> Void {
		if wasChosenWith == .left {
			print("Photo deleted!")
		} else {
			print("Photo saved!")
		}
	}
}

If you're using CocoaPods 0.36+ (perhaps because you want to include pods that contain Swift code) and you've included the use_frameworks! directive in your Podfile, then you've converted all your pods (including MDCSwipeToChoose) into frameworks. Therefore, you'll need to include the line

import MDCSwipeToChoose

...in your Swift files (even if you're using a bridging header).

More Generic Swiping

You don't have to use a subclass of MDCChooseView. You can use the mdc_swipeToChooseSetup: method on any UIView to enable swipe-to-choose.

In the following example, we adjust the opacity of a UIWebView when it's panned left and right.

#import <MDCSwipeToChoose/MDCSwipeToChoose.h>

// ... in a view controller

- (void)viewDidLoad {
    [super viewDidLoad];

    MDCSwipeOptions *options = [MDCSwipeOptions new];
    options.delegate = self;
    options.onPan = ^(MDCPanState *state){
        switch (state.direction) {
            case MDCSwipeDirectionLeft:
                self.webView.alpha = 0.5f - state.thresholdRatio;
                break;
            case MDCSwipeDirectionRight:
                self.webView.alpha = 0.5f + state.thresholdRatio;
                break;
            case MDCSwipeDirectionNone:
                self.webView.alpha = 0.5f;
                break;
        }
    };
    [self.webView mdc_swipeToChooseSetup:options];
}

##Swiping in Swift

The following is an example of how you can use MDCSwipeToChooseView to display a photo in swift. The user can choose to delete it by swiping left, or save it by swiping right.

First you must create a BridgingHeader.h file

#ifndef ProjectName_BridgingHeader_h
#define ProjectName_BridgingHeader_h


#import <UIKit/UIKit.h>
#import <MDCSwipeToChoose/MDCSwipeToChoose.h>

#endif

You must then add the bridging header file to the project by navigating to Build Settings then searching for 'Bridging Header'. Double click the field and type: ProjectName/BridgingHeader.h as the value

// Creating and Customizing a MDCSwipeToChooseView

override func viewDidLoad(){
    super.viewDidLoad()

    // You can customize MDCSwipeToChooseView using MDCSwipeToChooseViewOptions.
    let options:MDCSwipeToChooseViewOptions = MDCSwipeToChooseViewOptions()
    options.delegate = self
    options.likedText = "Keep"
    options.likedColor = UIColor.blue
    options.nopeText = "Delete"
    options.nopeColor = UIColor.red
    options.onPan = { state -> Void in
    if (state?.thresholdRatio == 1.0 && state?.direction == .left) {
        print("Let go now to delete the photo!")
    }
}

let view:MDCSwipeToChooseView = MDCSwipeToChooseView(frame:self.view.bounds, options:options)
    view.imageView.image = UIImage(named:"photo")
    self.view.addSubview(view)
}

// MDCSwipeToChooseDelegate Callbacks

// This is called when a user didn't fully swipe left or right.
func viewDidCancelSwipe(_ view: UIView) -> Void {
    print("Couldn't decide, huh?")
}

// Sent before a choice is made. Cancel the choice by returning `false`. Otherwise return `true`.
func view(_ view:UIView, shouldBeChosenWith: MDCSwipeDirection) -> Bool {
    if (shouldBeChosenWith == .left) {
        return true
    } else {
        // Snap the view back and cancel the choice.
        UIView.animate(withDuration: 0.16, animations: { () -> Void in
            view.transform = CGAffineTransform.identity
            view.center = self.view.center
        })
    return false
    }
}

// This is called when a user swipes the view fully left or right.
func view(_ view: UIView, wasChosenWith: MDCSwipeDirection) -> Void{
    if (wasChosenWith == .left) {
        print("Photo deleted!")
    } else {
        print("Photo saved!")
    }
}

Swiping programmatically

As of version 0.2.0, you may also swipe a view programmatically:

Objective-C

self.swipeToChooseView(mdc_swipe:MDCSwipeDirection.Left)
[self.swipeToChooseView mdc_swipe:MDCSwipeDirectionLeft];

Swift

self.swipeToChooseView.mdc_swipe(.left)

Disable swiping gesture

You may also disable the swiping gesture and only allowed to swipe programmatically

Objective-C

MDCSwipeToChooseViewOptions *options = [MDCSwipeToChooseViewOptions new];
options.swipeEnabled = NO;

Swift

let options = MDCSwipeToChooseViewOptions()
options.swipeEnabled = false

License

All the source code is distributed under the MIT license. See the LICENSE file for details. The license does not apply to the images used in the sample apps.