Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift - How to add addTarget on frontCardView? #95

Open
datomnurdin opened this issue Jul 6, 2015 · 2 comments
Open

Swift - How to add addTarget on frontCardView? #95

datomnurdin opened this issue Jul 6, 2015 · 2 comments

Comments

@datomnurdin
Copy link
Contributor

How to add addTarget on frontCardView so I can show profile details.

*.addTarget(self, action: "infoFrontCardView", forControlEvents: UIControlEvents.TouchUpInside)
@ghost
Copy link

ghost commented Jul 25, 2015

I'm using something like this

self.frontCardView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: Selector("tappedMe")))

func tappedMe() {
    performSegueWithIdentifier("loadProfileDetails", sender: nil)
}

@acegreen
Copy link

The above approach is "ok" though not optimal. Because the views are being removed, its best to put the UITapGestureRecognizer in the UIView+MDCSwipeToChoose class. I did the following:

  1. Add the gesture in mdc_swipeToChooseSetup function
  • (void)mdc_swipeToChooseSetup:(MDCSwipeOptions *)options {
    self.mdc_options = options ? options : [MDCSwipeOptions new];
    self.mdc_viewState = [MDCViewState new];
    self.mdc_viewState.originalCenter = self.center;

    [self mdc_setupPanGestureRecognizer];
    [self mdc_setupTapGestureRecognizer];
    }

  1. Add the tap gesture function itself
  • (void)mdc_onSwipeToChooseTapGestureRecognizer:(UITapGestureRecognizer *)tapGestureRecognizer {

    //printf("Tap Gesture");

    [[NSNotificationCenter defaultCenter] postNotificationName:@"performCustomSegue" object:nil];

}

Notification is not the best way to actually tell my viewController to perform the segue but the approach to add the gesture to the class is better than to the frontView. That way each view created conforms to both swipe and tap gesture and only the top view has user interaction enabled and taping it causes the actual segue to be performed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants