How can I switch views vertically using swipe gestures ?
5 Answers
I found my answer. I am posting the code for your reference. Thanks :-)
in viewDidLoad
UISwipeGestureRecognizer *swipeGesture = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedScreendown:)] autorelease];
swipeGesture.numberOfTouchesRequired = 1;
swipeGesture.direction = UISwipeGestureRecognizerDirectionDown;
[m_pImageView addGestureRecognizer:swipeGesture];
Now
- (void)swipedScreendown:(UISwipeGestureRecognizer*) swipeGesture {
m_pViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
CATransition *transition = [CATransition animation];
transition.duration = 0.75;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromBottom;
transition.delegate = self;
[self.view.layer addAnimation:transition forKey:nil];
[self.view addSubview:PadViewController.view];
}
If you need some more clarification please post here.
Implement this (didload)
//........towards right Gesture recogniser for swiping.....//
UISwipeGestureRecognizer *rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeHandle:)];
rightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[rightRecognizer setNumberOfTouchesRequired:1];
[urView addGestureRecognizer:rightRecognizer];
[rightRecognizer release];
//........towards left Gesture recogniser for swiping.....//
UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipeHandle:)];
leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[leftRecognizer setNumberOfTouchesRequired:1];
[urView addGestureRecognizer:leftRecognizer];
[leftRecognizer release];
Then This:
- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
//Do moving
}
- (void)leftSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
// do moving
}

- 10,094
- 10
- 68
- 109
-
Thanks rptwsthi. Can you please tell me in "do moving" what should I do ? Just loading of a viewController is fine ? – Akshay Jun 13 '11 at 05:34
-
Sorry for being late, Yes, you can load, controller or add sub view, but i don't have any clue that how will you animate that.. :I – rptwsthi Jun 13 '11 at 08:56
-
-
-
This work but the navigation is very quick. Anyway to slow it down or to work like Apple's (when in settings) – software is fun Aug 28 '15 at 17:28
-
For that you will probably have to work with pan gesture recogniser!! – rptwsthi Aug 28 '15 at 19:08
Certainly! Just set your viewController to be the UIGestureRecognizerDelegate
and declare UISwipeGestureRecognizer *swipeLeftRecognizer;
(also retain and synthesize). Then, in the implementation, set up the recognizers with
UIGestureRecognizer *recognizer;
// RIGHT SWIPE
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSwipeFrom:)];
[self.view addGestureRecognizer:recognizer];
[recognizer release];
// LEFT SWIPE
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
self.swipeLeftRecognizer = (UISwipeGestureRecognizer *)recognizer;
swipeLeftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeftRecognizer];
self.swipeLeftRecognizer = (UISwipeGestureRecognizer *)recognizer;
[recognizer release];
Then trigger the actions you want with the method
- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
// load a different viewController
} else {
// load an even different viewController
}
}
What you do here is specific to your app. You can switch the tabBar selection, jump through a navigationController, present a different view modally, or just do a simple slide in transition.

- 48,188
- 17
- 130
- 149
-
Thanks for your quick response PengOne. One more thing - I want that view to be loaded like a scrolling screen. How can I do that ? – Akshay Jun 13 '11 at 05:06
-
Animations... you can use a simple `UIViewAnimationTransition` or do a custom animation that's a little fancier. Google around for some nice examples. – PengOne Jun 13 '11 at 05:10
-
I know I saw a post a while back on SO that gave instructions for getting a nice sliding transition similar to the default for navigationControllers, but I couldn't find it just now. I'm sure you will find it with a few choice search words. Good luck! – PengOne Jun 13 '11 at 05:38
Adding gestures in swift
func addSwipes() {
// Left Swipe
let swipeLeft = UISwipeGestureRecognizer(target: self, action: "swipeLeft:")
swipeLeft.direction = .Left
self.view.addGestureRecognizer(swipeLeft)
// Right Swipe
let swipeRight = UISwipeGestureRecognizer(target: self, action: "swipeRight:")
swipeRight.direction = .Right
self.view.addGestureRecognizer(swipeRight)
}
func swipeLeft(gestureRecognizer: UISwipeGestureRecognizer) {
}
func swipeRight(gestureRecognizer: UISwipeGestureRecognizer) {
}

- 1,286
- 10
- 21
For reference PengOne, here is the code you referred to in your comment above. I saved it on my Mac because I thought it might be useful one day... :D
// Manual navigation push animation
UIImage* image = [UIImage imageNamed:@"CurrentView"];
UIImageView* imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = self.view.bounds;
[self.view addSubview:imageView];
[imageView release];
CATransition *transition = [CATransition animation];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[self.view.layer addAnimation:transition forKey:@"push-transition"];

- 803
- 2
- 9
- 22