Reputation: 378
I want to swipe in my app to push or pop ViewControllers , I know I can add a swipe gesture to that. But When I swipe the screen ,I want the current ViewController followed with my swipe gesture ,and next ViewController pushes in just with the swipe. How can I do this,Thank you!
Upvotes: 1
Views: 1136
Reputation: 5543
Not possible with UINavigationController
; you'll have to build your own navigation controller (should be pretty easy) that incorporates a UIPanGestureRecognizer
.
EDIT for iOS 7: You'll probably want to use a UIScreenEdgePanGestureRecognizer
.
Upvotes: 2
Reputation: 1760
Read about gesture recognizers. You can create them and add it on objects. For example
UILongPressGestureRecognizer *longTap = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(longPress:)];
longTap.minimumPressDuration = 1.0;
[cell addGestureRecognizer:longTap];
Here I have created LongPress recognizer and added it on my cell. If I will longpress(1.0 sec) on my cell, it will call selector(longPress:). In long press I can make any code.
-(void)longPress : (UILongPressGestureRecognizer *)rec {
if (rec.state == UIGestureRecognizerStateBegan) {
NSLog (@"I've longPressed");
}
}
You can use different recognizers by the same way.
About push and pop. They are methods of Navigation controller. Push - goes forward, on controller which you shows him;
NextController *goNext = [[NextViewController alloc] init];
[self.navigationController pushViewController:goNext animated:YES];
it will go to the NextController. Pop - backs to the previous controller.
Here you don't need to show the previous controller. Just say to navController back
[self.navigationController popViewControllerAnimated:YES];
Upvotes: 0
Reputation: 104082
Gesture recognizers have action methods just like buttons. Just put this in the action method:
NextViewController *next = [[NextViewController alloc] init ....];
[self.navigationController pushViewController:next animated:YES];
Upvotes: 1