Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to swap views using a swipe gesture XCode
    primarykey
    data
    text
    <p>I am using XCode to develop a Cocoa touch application for the iOS platform but have had trouble finding out how to get a swipe gesture implemented that would allow the user to swipe their finger left or right to change to a new <code>ViewController</code> (nib/xib file). I have done a <code>swapView IBAction</code> using a button and modal transitioning and I have read about Apple's <code>TouchGestureRecognizer</code> but I don't know how to implement a swipe action that would allow a view change.</p> <p>I do NOT want to use a scroll view, as I have several dozen view controllers, that I want the user to be able to swipe through.</p> <p>Here is an example:</p> <p>First View Controller.xib: SwipeRight- Go to second View Controller.xib</p> <p>Second View Controller.xib:<br> SwipeLeft- Go to first View Controller.xib<br> SwipeRight- Go to third View Controller.xib </p> <p>etc, etc</p> <p>I have not used UISwipe/Touch Gestures before but I have used an <code>IBAction</code> method to switch views using a button with Modal Transitioning (see below):</p> <pre><code>-(IBAction)swapViews; { SecondViewController *second2 =[[SecondViewController alloc initWithNibName:@"SecondViewController" bundle:nil]; second2.modalTransitionStyle = UIModalTransitionStyleCoverVertical; [self presentModalViewController:second2 animated:YES]; [second2 release]; } </code></pre> <p>Is using a swipe to do a similar method formatted differently? If so, how do I sort this out and format it. </p> <p>Thank You</p> <p><strong>Edit - Answer as Per Comment on Question</strong></p> <p>Place this in your viewDidLoad</p> <pre><code>UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeftDetected:)]; swipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft; [self.view addGestureRecognizer:swipeRecognizer]; [swipeRecognizer release]; </code></pre> <p>Then add a selector as by pasting the following code into your main...</p> <pre><code>- (IBAction)swipeLeftDetected:(UIGestureRecognizer *)sender { NC2ViewController *second2 =[[NC2ViewController alloc] initWithNibName:@"NC2ViewController" bundle:nil]; second2.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; [self presentModalViewController:second2 animated:YES]; [second2 release]; } </code></pre> <p>Then just make sure you import the otherViewController you are swapping to using</p> <pre><code>#import "SecondViewController" </code></pre> <p>at the top of your main file. Hope this helps.</p> <p><strong>End Edit</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload