1

I want to be able to open viewController B by pinching the screen on viewController A. Ideally I would like to be able to do this in Storyboard.

Any help/direction would be much appreciated.

Thanks

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Emré
  • 63
  • 5

1 Answers1

2

I'm not sure how far you can go in Storyboard directly, but the basic is you add a UIGestureRecogniser object and connect it to your view control and configure it for a pinch gesture. Then when the UIGestureRecogniser receives a pinch event it'll trigger the action you've hooked it up to, and you can trigger a segue event which you can also configure within the Storyboard, or you can push the new UIViewController onto the navigation stack.

Nicholas Smith
  • 11,642
  • 6
  • 37
  • 55
  • Hi Nicholas, so far I've used UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)]; [self.view addGestureRecognizer:pinchGesture]; than - (IBAction)handlePinchGesture:(id)sender { //((UIPinchGestureRecognizer *) sender).scale; if (((UIPinchGestureRecognizer *)sender).scale > 1.0) { AustraliaViewController *aust = [[AustraliaViewController alloc] initWithNibName:@"Australia" bundle:nil]; [self.navigationController pushViewController:aust animated:YES]; } } doesn't like it – Emré Jul 29 '13 at 15:01
  • Which part doesn't it like? If you can get it recognising the gesture then you're half way there. – Nicholas Smith Jul 29 '13 at 15:02
  • -[CTSViewController handlePinchGesture:]: unrecognized selector sent to instance 0x1ed630d0' When I connect the button to the other Viewcontroller Do I choose push/modal/custom? Thanks for the help by the way. – Emré Jul 29 '13 at 15:12
  • it is recognising the pinch gesture, but it's throwing the exception – Emré Jul 29 '13 at 15:14
  • Could you put the code into a Gist (https://gist.github.com/) just to make it a bit more readable. – Nicholas Smith Jul 29 '13 at 15:52
  • https://gist.github.com/anonymous/77b5001542c5c31a9694 I think this is the procedure.. Not entirely sure.. – Emré Jul 29 '13 at 15:59
  • Interesting, I just implemented it in a blank project and it doesn't throw any unrecognised selector issues. Try doing a clean build and going from there. – Nicholas Smith Jul 29 '13 at 16:11
  • Tried in a brand new project still no luck.. the console is showing the gesture activity. Am I trying to instantiate the AustraliaViewController in a wrong way? I've also tried this [self.storyboard instantiateViewControllerWithIdentifier:@"Australia"]; Doesn't work.. – Emré Jul 30 '13 at 09:07
  • It should just push it onto the navigation stack, so I'm not 100% sure why it wouldn't. Might be worth opening it as a new question. – Nicholas Smith Jul 30 '13 at 09:50