Giter Club home page Giter Club logo

mdcswipetochoose's Introduction

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.

mdcswipetochoose's People

Contributors

abury avatar alienxp03 avatar bergerjohannes avatar cgood avatar cph2117 avatar datomnurdin avatar farhanpatel avatar gjlondon avatar grantkemp avatar klundberg avatar kong707 avatar kt3k avatar mabeebam avatar mars avatar modocache avatar mokagio avatar neilkimmett avatar niho avatar pbrewczynski avatar readmecritic avatar reinitialized avatar rjburdish avatar thekie avatar tomblomfield avatar vikmeup 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mdcswipetochoose's Issues

[MDCSwipeOptions] exitScreenOnChosenWithDuration - configurable

Hi,
It'd be quite cool to have an ability to set that duration instead of having predefined 0.1 or overriding entire onChosen property. Can do PR for that by introducing another static property to header file e.g.

@property (nonatomic, assign) NSTimeInterval exitScreenAnimationDuration;

instead of

options.onChosen = [MDCSwipeOptions exitScreenOnChosenWithDuration:0.5 options:UIViewAnimationOptionCurveLinear];

What do you think?

Method 'setFrontCardView' with Objective-C selector 'setFrontCardView:' conflicts with setter for 'frontCardView' with the same Objective-C selector

I got this two error messages after updated xcode 6.3.1.

/Users/MNurdin/Documents/Github/MDCSwipeToChoose/Examples/SwiftLikedOrNope/SwiftLikedOrNope/ChoosePersonViewController.swift:111:10: Method 'setFrontCardView' with Objective-C selector 'setFrontCardView:' conflicts with setter for 'frontCardView' with the same Objective-C selector

Code

func setFrontCardView(frontCardView:ChoosePersonView) -> Void{

        // Keep track of the person currently being chosen.
        // Quick and dirty, just for the purposes of this sample app.
        self.frontCardView = frontCardView
        self.currentPerson = frontCardView.person
    }

Please advice. Thank you.

Animated Gif?

Hello,

This isn't an issue, just a simple question for the author. I really like the animated gif you have when demoing the functionality of your app! How did you do it/what software did you use? Thank you so much!

Best,
Bennett

Programmatic mcd_swipe

Should clarify in the docs that the user has to manually call wasChosenWithDirection when using the mdc_swipe function on the MDCSwipeToChooseView.

In my case, the front card view would not be removed either.
Here's a basic sample of getting it to work:

[self.frontCardView mdc_swipe:MDCSwipeDirectionLeft];
[self.frontCardView removeFromSuperview];
[self view:self.swipeView wasChosenWithDirection:MDCSwipeDirectionLeft];
[self.frontCardView mdc_swipe:MDCSwipeDirectionRight];
[self.frontCardView removeFromSuperview];
[self view:self.swipeView wasChosenWithDirection:MDCSwipeDirectionRight];

fatal error: unexpectedly found nil while unwrapping an Optional value

I got this error message in ChoosePersonView.swift.

init(frame: CGRect, person: Person, options: MDCSwipeToChooseViewOptions) {

        super.init(frame: frame, options: options)
        self.person = person

        self.imageView.image = self.person.Image! //error here
        self.autoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth
        UIViewAutoresizing.FlexibleBottomMargin

        self.imageView.autoresizingMask = self.autoresizingMask
        constructInformationView()
    }

Can this library be modified to have a third swipe direction?

Hi,

Besides swiping the card left or right for 'skip' or 'add' respectively, I need to give the user the option to swipe down to mark 'seen'.

How do I go about modifying the MDCSwipeToChoose library? Is this structurally possible?

Any guidance in this regards will help me tremendously.

Thanks,
Varun

How do I to make 3 cards?

Hi thanks for sharing , how do I to make 3 cards like tinder, ? I tried but did not worked

Thanks

Animation for Liked and Nope button does not work

When user tap Liked or Nope button . The action works correctly except that the frontView is completely disappear without any animation . How can I solve this ? The example app works just fine .But when I use it on my project ,it does not work.

Absolute value function 'fabsf' given an argument of type 'CGFloat' (aka 'double') but has parameter of type 'float' which may cause truncation of value

I got this warning message after update latest pod.

/Users/MNurdin/Documents/iOS/xxxxx/Pods/MDCSwipeToChoose/MDCSwipeToChoose/Public/Views/UIView+MDCSwipeToChoose.m:170:43: Absolute value function 'fabsf' given an argument of type 'CGFloat' (aka 'double') but has parameter of type 'float' which may cause truncation of value

Code

- (void)mdc_executeOnPanBlockForTranslation:(CGPoint)translation {
    if (self.mdc_options.onPan) {
        CGFloat thresholdRatio = MIN(1.f, fabsf(translation.x)/self.mdc_options.threshold);

        MDCSwipeDirection direction = MDCSwipeDirectionNone;
        if (translation.x > 0.f) {
            direction = MDCSwipeDirectionRight;
        } else if (translation.x < 0.f) {
            direction = MDCSwipeDirectionLeft;
        }

        MDCPanState *state = [MDCPanState new];
        state.view = self;
        state.direction = direction;
        state.thresholdRatio = thresholdRatio;
        self.mdc_options.onPan(state);
    }
}

Please check my pull request.

#74

not usable in interface builder, and other design issues

I love MDCSwipeToChoose! It works great and I was thrilled when I saw the demo app.

There's a problem, though. You can't use it in interface builder because MDCSwipeToChooseView uses a custom initializer. That forces me to do manual layout for my views, which is really tragic. Or I can use complicated wrappers to load my subviews from nibs and stuff them into an MDCSwipeToChooseView subclass.

It would be better to refactor into a traditional collection/subview model, like UITableView, UICollectionView, etc. See ZLSwipeableView for a design example. ZLSwipeableView is an interesting case - I'm not crazy about the control behavior but the API design is very nice.

This would have additional benefits too:

  1. would make it possible to remove the UIVIew category
  2. the container class could handle card layout and front/back logic
  3. put options in one place (instead of every card)

Thanks for making such a nice control!

Disable swipe, only use the upvote and downvote button

Hi,

At first, thank you so much for the amazing work!

I would like to disable the swiping between images to upvote or downvote. I would only like to use the green and red thumb for upvote or downvote.

How can I make this possible? I found the void setupSwipeToChoose but when I remove this the first image will work, the second image will be stuck on the screen.

Thank you!

Swift - Custom UIView

I can't create custom UIView properly inside my view controller. What I want is four buttons (UNDO, DISLIKE, LIKE, INFO) in vertical side. But my UNDO and INFO button not appeared properly inside my view controller.

let ChoosePersonButtonHorizontalPadding:CGFloat = 40.0
let ChoosePersonButtonVerticalPadding:CGFloat = 20.0

func constructUndoButton() -> Void{
        let button:UIButton =  UIButton.buttonWithType(UIButtonType.System) as UIButton
        let image:UIImage = UIImage(named:"undo")!
        button.frame = CGRectMake(ChoosePersonButtonHorizontalPadding, CGRectGetMaxY(self.backCardView.frame) + ChoosePersonButtonVerticalPadding, image.size.width, image.size.height)
        button.setImage(image, forState: UIControlState.Normal)
        button.addTarget(self, action: "undoFrontCardView", forControlEvents: UIControlEvents.TouchUpInside)
        self.view.addSubview(button)
    }

    func constructNopeButton() -> Void{
        let button:UIButton =  UIButton.buttonWithType(UIButtonType.System) as UIButton
        let image:UIImage = UIImage(named:"nope")!
        button.frame = CGRectMake(ChoosePersonButtonHorizontalPadding, CGRectGetMaxY(self.backCardView.frame) + ChoosePersonButtonVerticalPadding, image.size.width, image.size.height)
        button.setImage(image, forState: UIControlState.Normal)
        button.addTarget(self, action: "nopeFrontCardView", forControlEvents: UIControlEvents.TouchUpInside)
        self.view.addSubview(button)
    }

    func constructLikedButton() -> Void{
        let button:UIButton = UIButton.buttonWithType(UIButtonType.System) as UIButton
        let image:UIImage = UIImage(named:"liked")!
        button.frame = CGRectMake(CGRectGetMaxX(self.view.frame) - image.size.width - ChoosePersonButtonHorizontalPadding, CGRectGetMaxY(self.backCardView.frame) + ChoosePersonButtonVerticalPadding, image.size.width, image.size.height)
        button.setImage(image, forState:UIControlState.Normal)
        button.addTarget(self, action: "likeFrontCardView", forControlEvents: UIControlEvents.TouchUpInside)
        self.view.addSubview(button)

    }

    func constructInfoButton() -> Void{
        let button:UIButton = UIButton.buttonWithType(UIButtonType.System) as UIButton
        let image:UIImage = UIImage(named:"info")!
        button.frame = CGRectMake(CGRectGetMaxX(self.view.frame) - image.size.width - ChoosePersonButtonHorizontalPadding, CGRectGetMaxY(self.backCardView.frame) + ChoosePersonButtonVerticalPadding, image.size.width, image.size.height)
        button.setImage(image, forState:UIControlState.Normal)
        button.addTarget(self, action: "infoFrontCardView", forControlEvents: UIControlEvents.TouchUpInside)
        self.view.addSubview(button)

    }

Result (ignore the image and button colour part)

screen shot 2015-04-08 at 10 11 57 am

What I want

screen shot 2015-04-08 at 9 59 19 am

Please advice.

Initializer does not override a designated initializer from its superclass

I got this two error messages after updated xcode 6.3.1.

/Users/MNurdin/Documents/Github/MDCSwipeToChoose/Examples/SwiftLikedOrNope/SwiftLikedOrNope/ImageLabelView.swift:32:14: Initializer does not override a designated initializer from its superclass

/Users/MNurdin/Documents/Github/MDCSwipeToChoose/Examples/SwiftLikedOrNope/SwiftLikedOrNope/ImageLabelView.swift:33:9: Must call a designated initializer of the superclass 'UIView'

Code

override init(){
        super.init()
        imageView = UIImageView()
        label = UILabel()
    }

Please advice. Thank you.

Liked and Nope images

How do the green liked and red nope images fade in on the image as you swipe? I don't see those images anywhere and I can't find that functionality in the code.

When delegate forbids a choice, the view won't return to initial state

What I'd expect:

returning NO from

- (BOOL)view:(UIView *)view shouldBeChosenWithDirection:(MDCSwipeDirection)direction;

would throw the view to its initial state.

What actually happens:

view remains in the same position as it was after last dragging.

Workaround

manually call mdc_returnToOriginalCenter.

Suggested solution
Since mdc_returnToOriginalCenter is private, I think it'd be great to either make it public or modify mdc_exitSuperviewFromTranslation in the following manner:

    if ([delegate respondsToSelector:@selector(view:shouldBeChosenWithDirection:)]) {
        BOOL should = [delegate view:self shouldBeChosenWithDirection:direction];
        if (!should) {
            [self mdc_returnToOriginalCenter]; //< added
            return;
        }

(note that it now includes a call to mdc_returnToOriginalCenter)

Another problem is that you'd need to hack around to restore the view's state in this case, i.e. if you were overlaying something on top of the view, no appropriate callbacks will be called. It seems like adding onCancel block property to accompany MDCSwipeOptions's onPan and onChosen would be a viable solution and won't get anyone into compatibility troubles.

I would provide a PR if you agree that this is a problem and my solution will be good enough.

BTW, thanks for saving us a few hours of work with this thing! :)

Initial image is too big.

Initial image is too big in swift project. How to make it fit inside view controller?

2015-03-30 04 25 28

But it's ok for second image.

2015-03-30 04 25 33

Memory Leak

Grateful for such a great control, I am in the process of using each Liked or Nope will have a memory leak. May I ask how to deal with memory leaks?
Content from GOOGLE translation problem.

originalCenter is only updated once

In my application, I create the swipe to choose views before setting the frame. This causes some problems when swiping a view programmatically, because it does not update the originalCenter before swiping the view programmatically.

For instance, the center is incorrect so swipe is "cancelled" (because of mdc_directionOfExceededThreshold which uses originalCenter to calculate if the view has exceeded the threshold) and animates back to the originalCenter, which is not where it was before. Maybe mdc_swipe: should update the originalCenter before it 'swipes' the view?

Just a suggestion. I got around this by setting the frames when I create the views.

Thanks for this! It's very well written and saved me a lot of time.

Initializer does not override a designated initializer from its superclass

I got this two error messages after updated xcode 6.3.1.

/Users/MNurdin/Documents/Github/MDCSwipeToChoose/Examples/SwiftLikedOrNope/SwiftLikedOrNope/ChoosePersonViewController.swift:46:14: Initializer does not override a designated initializer from its superclass

/Users/MNurdin/Documents/Github/MDCSwipeToChoose/Examples/SwiftLikedOrNope/SwiftLikedOrNope/ChoosePersonViewController.swift:47:9: Must call a designated initializer of the superclass 'UIViewController'

Code

override init(){
        super.init()
    }

Please advice. Thank you.

BackCard Animation

Hi,

How do you get the backCard to animate from a smaller frame to a bigger frame when the frontCard is being swept away in either direction? Like the UX seen on Tinder where each card is a little smaller in width from the previous one but the width grows as the front card is being swept away.

Thanks,
Varun

Custom Nope & Liked Views

I'm trying to use a UIImageView as a custom view for the nope and liked views like so:

 MDCSwipeToChooseView *view = [[MDCSwipeToChooseView alloc] initWithFrame:swipeFrame
                                                                 options:options];
UIImageView *likedView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[likedView setImage:[UIImage imageNamed:@"LikedImage"]];

view.likedView = likedView;

view.imageView.image = [UIImage imageNamed:@"ImageName"];

But nothing changes. Don't know why that should happen, considering view.imageView is obviously mutable. I also tried using a custom label instead of an imageView for testing purposes to no avail.

LikeOrNope in swift

I have implemented MDCSwipeToChoose into a swift project and have the view controller currently swiping, however I am having alot of trouble getting the graphics down and loading the stack as it is done in likeornope.. Is there any chance there is a swift version of likeornope available or will one be coming soon. I think I speak for many new IOS developers by saying this would be extremely useful.

Thanks,
Rich

Property 'superview' not found on object of type 'ViewController *'

I got this error message in this code

- (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 = self.superview.center;
        }];
        return NO;
    }
}

pod install isn't working on LikedOrNope project

After entering pod install in the LikedOrNope directory, I am getting this error.

MacBook-Pro:LikedOrNope varungoel$ pod install
Analyzing dependencies
/Users/varungoel/.rvm/gems/ruby-2.0.0-p353@global/gems/cocoapods-0.33.1/lib/cocoapods/executable.rb:55: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
[!] An error occurred while performing git pull on repo master.
[!] /usr/bin/git pull --ff-only

error: RPC failed; result=56, HTTP code = 200

fatal: The remote end hung up unexpectedly

fatal: early EOF

fatal: index-pack failed

Has anyone been able to install this pod successfully?

Can't do pod install

I can't install pod for swift project.

diff: /../Podfile.lock: No such file or directory
diff: /Manifest.lock: No such file or directory
error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.

Swift code getting <Error>: CGAffineTransformInvert: singular matrix

While using Swift code If any card is clicked by choosing the buttons instead of Pan gesture - the animation is not showing up.

In Xcode console we see this error.

SwiftLikedOrNope[3704] <Error>: CGAffineTransformInvert: singular matrix

Tried to fix this by initializing originalTransform in UIView+MDCSwipeToChoose.m

self.mdc_viewState.originalTransform = CGAffineTransformMake(1, 0, 0, 1, 0, 0);

Donno is this the right way or not, comment or suggest a better solution. If our approach is right, let me know if you want me to make a pull request and check in the code.

Undo

It could be a nice feature to be able to undo the last swipe?

Compatibility without the -objC linker flag

Thanks for the amazing work! I currently building an app that also requires facebook sdk. The facebook requires that I cant have the -objC linker flag which causes this library to break.

Is there a way to make this library work without the -objC linker flag?

Assigning to 'id<MDCSwipeToChooseDelegate>' from incompatible type 'ViewController *const __strong'

I got warning message for this code

- (void)viewDidLoad {
    [super viewDidLoad];

    // You can customize MDCSwipeToChooseView using MDCSwipeToChooseViewOptions.
    MDCSwipeToChooseViewOptions *options = [MDCSwipeToChooseViewOptions new];
    options.delegate = self; // warning message
    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:@"finn"];
    [self.view addSubview:view];
}

Swiping A View Programmatically

Im trying to swipe a View Programmatically but [self.swipeToChooseView mdc_swipe:MDCSwipeDirectionLeft]; has not been working.Am i doing something wrong?

I can't install pod

When I try typing pod install in the directory of example, I received many errors and do not install the pods folder

Swift adoption.

Hey. I tried installing this component via pods to use it with Swift, but got an error which I cant figure out how to fix (as I know zero Objective-C). Maybe some1 could take a quick look ? Cheers in advance !

I created a new new project.
did pod init inside.
added pod "MDCSwipeToChoose" to Podfile.
ran pod install
Opened the newly created workspace.
created BridgingHeader.h file.
Added #import <MDCSwipeToChoose/MDCSwipeToChoose.h>
Added BridgingHeader.h path to apps target Swift Compiler - Code Generator section.

And got an error inside MDCSwipeToChooseDelegate.h file:
screen shot 2014-10-24 at 21 48 41
screen shot 2014-10-24 at 21 46 41
screen shot 2014-10-24 at 21 46 30

Incorrect behaviour in ios7 with constraints

In ios 7, when the view is using autolayout with constaints, it only rotates when doing pan, it seems that

view.center = MDCCGPointAdd(self.mdc_viewState.originalCenter, translation);

isn't working properly in this case (in ios8 it works as expected). What I did to solve this is instead of changing the center property I changed the constraints values, I couldn't figure out another solution. It would be something like this:

[self updatePositionWithDelta: [gestureRecognizer translationInView:self.superview];];

(void) updatePositionWithDelta:(CGPoint)delta {
self.topSpace.constant = originalTop + delta.y;
self.bottomSpace.constant = originalBottom - delta.y;

self.leadingSpace.constant = originalLeading + delta.x;
self.trailingSpace.constant = originalTrailling - delta.x;

[self updateConstraintsIfNeeded];
}

Hope it helps improving the control.

Swipe handling doesn't take velocity into account

When swiping, the pan gesture recognizer doesn't account for the velocity of the swipe when the gesture completes. This means that a short flick, which feels like it should send the card off-screen, moves the card slightly and returns it back to the center.

This should be a relatively simple process of passing the pan gesture recognizer to the finalization method so that the velocity can be accessed and processed.

onChosen default animation is incorrect

The current animation performed when a card is chosen changes the frame of the card. This is not correct, because the frame won't be correctly changed since there is a transform applied to the card. UIView documentation says that only bounds and center should be changed when a transform is present.

There is a simple fix, though. Instead of changing the frame, just change the center to the center of the newly calculated frame.

How do i build my own custom view

I want my own custom view .
the View will have an image and some labels at image bottom like in tinder.
how can i do this ?
Please tell me

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.