I use Xcode to develop a Cocoa touchscreen application for the iOS platform, but I'm having trouble finding how to implement a realistic gesture that allows the user to swipe left or right to switch to the new ViewController (nib / xib file). I did a swapView IBAction with a button and a modal transition, and I read about Apple TouchGestureRecognizer , but I donβt know how to implement a swipe action that will change the look.
I DO NOT want to use scrolling, since I have dozens of view controllers that I want the user to scroll through.
Here is an example:
First View Controller.xib: SwipeRight - transition to the second View Controller.xib
Second View Controller.xib:
SwipeLeft - Go to the first View Controller.xib
SwipeRight - transition to the third View Controller.xib
etc.
I have not used UISwipe / Touch Gestures before, but I used the IBAction method to switch views using a button with Modal Transitioning (see below):
-(IBAction)swapViews; { SecondViewController *second2 =[[SecondViewController alloc initWithNibName:@"SecondViewController" bundle:nil]; second2.modalTransitionStyle = UIModalTransitionStyleCoverVertical; [self presentModalViewController:second2 animated:YES]; [second2 release]; }
Does the napkin use a similar method, formatted differently? If so, how can I sort and format it.
thanks
Edit - answer as a comment on the question
Put it in your view
UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeftDetected:)]; swipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft; [self.view addGestureRecognizer:swipeRecognizer]; [swipeRecognizer release];
Then add a selector by pasting the following code into your main ...
- (IBAction)swipeLeftDetected:(UIGestureRecognizer *)sender { NC2ViewController *second2 =[[NC2ViewController alloc] initWithNibName:@"NC2ViewController" bundle:nil]; second2.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; [self presentModalViewController:second2 animated:YES]; [second2 release]; }
Then just make sure you import another ViewView control that you change using
#import "SecondViewController"
at the top of your main file. Hope this helps.
Edit end