I have updated to IOS 13 and now, I am not able to use left swipe to go to previous view controller in navigation controller.
Can you suggest how to solve that issue?
Thanks
If you struggle displaying UINavigationController within a modal, You can try this:
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return gestureRecognizer == self.navigationController.interactivePopGestureRecognizer;
}
Related
This question already has answers here:
How to disable back swipe gesture in UINavigationController on iOS 7
(18 answers)
Closed 6 years ago.
i have two view in my app there are one button in first view so when i click on this button then second view open
My problem is on second view when i horizontally swipe or scroll then why first view open without logout process or back button action perform?
please some one help me
You must have push to the second view ,
This is default behaviour of iOS after iOS 7.
You need to add this code for iOS 8
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if ([self.navigationController respondsToSelector:#selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if ([self.navigationController respondsToSelector:#selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
}
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
return NO;
}
For more information , Please follow this link
Hope this helps!.
This is default behavior when you push new view controller into navigation stack.
You can disable this behavior by setting interactivePopGestureRecognizer.enabled to false
In my application I am using the standard UIViewController structure around my app. However I have views which I transition to using a UIStoryboardSegue push. In that UIViewController I am doing this in the viewDidLoad:
self.navigationController.interactivePopGestureRecognizer.delegate = self;
Then I have this delegate method as well to enable the swipe back gesture:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
The problem is, in my original view I presented from, I present a custom menu programmatically in the viewWillAppear using a typical approach like this:
[self.view addSubview:menu];
This works fine if I were to go back to my main menu using
[[self navigationController] popViewControllerAnimated:YES];
However, if I use the swipe back gesture, the view never presents even though the viewWillAppear clearly is called. Is my UINavigationController the issue for this or is something else going on here that I simply do not see?
I have a UINavigationBar that intercepts the back button tap that alerts the user if there are unsave changes. This is based on the solution presented in UINavigationController and UINavigationBarDelegate.ShouldPopItem() with MonoTouch using the UINavigationBarDelegate protocol and implementing - (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item;
Now, iOS7 has introduced the swipe-to-go-back gesture, and I'd like to intercept that as well, but can't get it to work with the solutions I've found so far, namely using [self.interactivePopGestureRecognizer addTarget:self action:#selector(handlePopGesture:)]; and
- (void)handlePopGesture:(UIGestureRecognizer *)gesture {
if (gesture.state == UIGestureRecognizerStateEnded) {
[self popViewControllerAnimated:NO];
}
}
While this does pop the views, it leaves the navigation bar buttons in place, so I'm ending up with a back button that leads nowhere, as well as all other navigation button I've added to the nav bar. Any tips?
To intercept the back swipe gesture you can set self as the delegate of the gesture (<UIGestureRecognizerDelegate>) and then return YES or NO from gestureRecognizerShouldBegin based on unsaved changes:
// in viewDidLoad
self.navigationController.interactivePopGestureRecognizer.delegate = self;
// ...
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
if ([gestureRecognizer isKindOfClass:[UIScreenEdgePanGestureRecognizer class]]) {
if (self.dirty) {
// ... alert
return NO;
} else
return YES;
} else
return YES;
}
In the alert you can ask to the user if she want to go back anyway and, in that case, pop the controller in alertView clickedButtonAtIndex:
Hope this is of some help.
I am using good control SWRevealViewController, but by some redone I want to track my own swipe gestures on my screen. So how can I switch off swipe options? I want to work only revealToggle method that attached to my button. Did someone faced with this? Thank you
In order to disable the swipe gesture you can simple do:
self.revealViewController.panGestureRecognizer.enabled=NO;
For example:
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.revealViewController.panGestureRecognizer.enabled=NO;
}
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
self.revealViewController.panGestureRecognizer.enabled=YES;
}
In your viewDidLoad method,type the below code where you don't want to enable the swipe gesture:
SWRevealViewController *reveal = self.revealViewController;
reveal.panGestureRecognizer.enabled = NO;
I found this method:
for (UIGestureRecognizer *recognizer in self.view.gestureRecognizers) {
[self removeGestureRecognizer:tap];
}
To stop the swipe in the SWRevealViewController:
In Swift 3.0
self.revealViewController().panGestureRecognizer().isEnabled = false
In iOS apps, there is a default gesture that swipe from the left edge to right the app navigationController will pop view controller.
But is there a way to disable it for specific view?
You can disable it through the public API, See UINavigationController Class Reference
//iOS7 Customization, swipe to pop gesture
if ([navigationController respondsToSelector:#selector(interactivePopGestureRecognizer)]) {
navigationController.interactivePopGestureRecognizer.enabled = NO;
}
Also, you can switch back to previous state when needed
if(navigationController) {
if ([navigationController respondsToSelector:#selector(interactivePopGestureRecognizer)]) {
navigationController.interactivePopGestureRecognizer.enabled = NO;
}
}
its possible but may be a cause for you app rejection
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}