1

I'd like to be able to navigate to another viewController by pinching view on the current viewController.

The console shows that the view is recognising the pinch gesture and it logs it.

However I'm not clear on how I can trigger the pinch to open another ViewController.

Here is the code that I've used to implement this.

- (void)viewDidLoad
{
    [super viewDidLoad];

    //Pinch Gesture
    UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];
    [self.view addGestureRecognizer:pinchGesture];
} 


- (IBAction)handlePinchGesture:(UIPinchGestureRecognizer *)sender
{

    NSLog(@" ((UIPinchGestureRecognizer *) sender).scale %f", ((UIPinchGestureRecognizer *) sender).scale);
    if (((UIPinchGestureRecognizer *)sender).scale > 1.0)
    {
        //I tried to use a different method to instantiate AustraliaViewController but it    //doesn't work 
        //[self.storyboard instantiateViewControllerWithIdentifier:@"Australia"];

        AustraliaViewController *aust = [[AustraliaViewController alloc] initWithNibName:@"Australia" bundle:Nil];
        aust.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [self presentViewController:aust animated:YES completion:Nil];
    }

        [self showInfo:(id)sender];

}
Emré
  • 63
  • 5
  • Is the code within the if statement executed? – dasdom Jul 30 '13 at 12:32
  • Yes it is. I've tried both the Alloc init and [self.storyboard instantiateViewControllerWithIdentifier:@"Australia"]; separately but no luck. – Emré Jul 30 '13 at 12:46
  • Have you tried to use `presentModalViewController`? – dasdom Jul 30 '13 at 12:49
  • Just tried it. No good..I should mention that I'm doing this in Storyboard. Do I have to connect the - (IBAction)handlePinchGesture:(UIPinchGestureRecognizer *)sender to anything on storyboard? – Emré Jul 30 '13 at 13:03
  • 1
    If the `handlePinchGesture:` method is called and it goes into the if then you don't need to change anything is storyboard. Do you have an XIB named "Australia" or a view controller in the storyboard with "Australia" as the identifier. If you debug I guess `aust` is nil. – Wain Jul 30 '13 at 15:52
  • I have a view controller in storyboard with Australia as the identifier. – Emré Jul 30 '13 at 16:01
  • 1
    So you should be using the storyboard instantiation method. Debug to check you're getting the instance. Is the current controller created from the storyboard (or is the storyboard `nil` too)? – Wain Jul 31 '13 at 08:22
  • Current View Controller ---- self.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Race"]; I will debug. I don't quite know how to debug to see if aust or storyboard is returning nil. – Emré Jul 31 '13 at 10:05
  • breakpoint the line just after, then in the debugger: `po aust` – Wain Jul 31 '13 at 10:18

0 Answers0