ios,How to preform (interactivePopGestureRecognizer )back action in Collection view - ios

ListViewController-> DetailsViewController, the navigationController of the DetailsViewController support interactivePopGestureRecognizer feature, that can swipe right and back to ListViewContorller, it is fine,
just the DetailsViewController contains some UICollectionView, it does not response the swipe gesture, it is meaning if user touch the CollectionView swipe,drag the view from left to right, the navigationController not got the action at all, how to solve this problem ?
I just try this way:
[collectionView addGestureRecognizer: self.navigationController.interactivePopGestureRecognizer];
but it not works .
so then I create new 'Swipe Gesture Recognaizer' and bind to collectionView, also link to the selector action as bellow:
I add code in the details view:
-(IBAction)swipeBack:(id)sender
{
[self.navigationController popToRootViewControllerAnimated:true];
}
then, if user touch the collectionView, then it can back to list view controller, but it not is good enough, because it not works the same to 'interactivePopGestureRecognizer',
anyone know other best solution for this purpose ? thanks for your time.

Like it is mentioned in https://stackoverflow.com/a/18947952/1113407 multiple gesture work better if
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
is set.
If that is not enough, try adopting https://stackoverflow.com/a/2628777/1113407 for your needs.
In UINavigationContoller swipe back function not working if its view is added to UIViewContoller "Mr.1" mentioned:
Updated: It turns out that if the navigation bar is hidden, the swipe function will be disabled....
Did you hide the navigation bar?

Related

Screen edge gesture when using UISplitViewController with hidden navigation bar

In an iPhone app, we have the ability to hide the navigation bar. By default, calling [self.navigationController setNavigationBarHidden:YES animated:YES] to hide the navigation bar stops the screen edge gesture recognizer self.navigationController.interactivePopGestureRecognizer from working, but in the past I could restore this functionality by setting its delegate to my own (while the bar is hidden) that does this:
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return ![otherGestureRecognizer isKindOfClass:[UIScreenEdgePanGestureRecognizer class]];
}
However, this doesn't work now that the app is using UISplitViewController.
It's unclear if the split view controller is using its own gesture recognizer, or some other issue. I haven't been able to figure out how to make it work.
I can't find any other discussion on this. The most recent posts I've found are years old, e.g. this one, this one, or this one.
What am I missing? How can I get a screen edge interactive gesture to work with UISplitViewController when the navigation bar is hidden?
Thank you rubber duck. 🐥
Of course, soon after posting that, I figured out the answer: when in compact layout, e.g. on iPhone, the UISplitViewController has a UINavigationController to manage the hierarchy, plus the detail view controller has its own UINavigationController.
So the solution was to use the interactivePopGestureRecognizer of the outer navigation controller (that has multiple view controllers), not the inner one (with only one), thusly:
#objc var parentNavigationController: UINavigationController? {
return navigationController?.parent as? UINavigationController
}
I hope this helps someone else encountering this issue.

CAPSPageMenu swipe and side menu swipe conflict in iOS

I'm using CAPSPageMenu (https://github.com/PageMenu/PageMenu) in my app. I have side menu (ECSlidingViewController - https://github.com/ECSlidingViewController/ECSlidingViewController). Now if the side menu is opened I want to disable the swipe gesture of pagemenu and If user swipe the side menu should close. Currently what's happening is if side menu open and the user swipe pagemenu is changing page. How can we acheive this?
Here's the code to disable swipe in page menu
_pagemenu.controllerScrollView.scrollEnabled = NO;
How I tried is I wrote one call back in the side menu tap and I try to reload the pagemenu according to that. But it is not working.
if (self.menuCallBack) {
_pagemenu.controllerScrollView.scrollEnabled = NO;
} else {
_pagemenu.controllerScrollView.scrollEnabled = YES;
}
And how can avoid swipe after last page. I'm having 3 screens. If we swipe after 3rd screen it is showing some blank view how can we avoid this?
Any help could be appreciated. Thanks in advance.
ECSlidingViewController is making use of Pan gesture for detecting the horizontal swipe. CAPS pagemenu uses scrollview. The ECSlidingViewController must not be receiving the gesture, even if scrollview is disabled on CAPSPageMenu class.
Try this code on your CAPSPagemenu class:
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}

iOS gesture collisions between slider and pan gesture on controller

I am using ECSlidingViewController for hamburger menu and I added code to my viewDidLoad method:
[self.slidingViewController.topViewController.view addGestureRecognizer:self.slidingViewController.panGesture];
Now I have pan gesture to show right menu or to hide. It's okay. But I have on view slider and it's really hard to get him working. I must tap on exact position. Is it possible to set that in exact rectangle (in view that contains slider) the slider would be answering on gesture and on other parts it would be working as now?
And one more question. When I have navigation controller with table and then I went on detail and then I show right menu it's okay but when I want to close it by pan I first go back in navigation and then close menu. Is it possible to change this order?
Have you tried setting UIGestureRecognizerDelegate and handling the both gesture recognizes in similar fashion as described in FAO?
e.g.:
#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
if ([otherGestureRecognizer.view isKindOfClass:[UISlider class]]) {
return YES;
} else {
return NO;
}
}

Passing UIGestureRecognizer events to child TableViewCells

I currently have a setup of:
A RootVC, with a UIPanGestureRecognizer on self.view. Then the RootVC has a child UITableViewController and hence UITableViewController.view is a subview of self.view.
The cells on the UITableViewController also have gesture recognizers enabling them to be swiped sideways. This works perfectly when the UITableViewController is itself the root view controller.
My issue is that im trying to pass a specific gesture from the self.view gesture recognizer down to the table cells. I've tried delegates:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
and
-(BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer
I can correctly identify the gestures i want to be sent below and return NO in that instance but that seems to cancel the gesture instead of passing it to subviews.
I know i could just call
[self.view.subviews[0] gestureShouldBegin:gestureRecognizer];
But because its the table view cells i cannot determine which cell the gesture should be sent too.
I have been thinking something like
[[self.childViewControllers[0] cellForRowAtIndexPath:indexPath] gestureShouldBegin:gestureRecognizer];
Would work but i dont know how to determine the correct indexPath..
Any ideas?
Look at (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point
You'll need to translate the point of the gesture to the coordinates for the tableView first.

iPad - PageViewController - Show next view controller on button click

I'm using UIPageViewController in my application that shows all the images similar to a book. Its working fine.
What I want to do now:
I want to place a button on top left corner and on click it will show a pop over view controller which has a table view with 7 cells. Each cell will show different URL. On click of the table cell, it will push a view controller with web view.
What's the problem
The problem is that I placed the button on top left and created a segue to show popover. But on click of button it goes to previous page and on next clicks it will finally reach page 1. then in page 1, it will show the pop over. I didn't understand why is it happening like this.
And even after showing popover, its not showing next view with website.
How to do it?
The trick is that UIPageViewController's gesture recognizers take over that area. In particular, the tap handler; so your button only gets hit when the tap recognizer does not take it as meaning to go to the previous page.
Quickest solution is to set yourself to the delegate of its recognizers
for (UIGestureRecognizer *recognizer in pageViewController.gestureRecognizers)
recognizer.delegate = self;
and then implement the delegate telling them to let controls get touches
- (BOOL)gestureRecognizer:(UIGestureRecognizer *) __unused gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if ([touch.view isKindOfClass:[UIControl class]])
return NO;
return YES;
}
which ought to sort you nicely.

Resources