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.
Related
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;
}
I have a setup where I have a Page View Controller set up to navigate between different views.
In some of these views I will have a custom drawing view where the user can draw with their finger to create a picture.
The problem with this, the user is not able to make a drawing gesture left/right because the page view controller will take over and navigate to a different view.
I was wondering what a good approach would be to temporarily disable the swiping for the page view controller to allow the user to draw.
I was thinking when the user first interacts with the drawing view it would disable the page swiping and create a finished drawing button. When this button is clicked it would reenable the page swiping. Does this seem reasonable, or does anybody know of any better approaches?
Using this you can stop Scrolling
for (UIScrollView *view in self.pageViewController.view.subviews) {
if ([view isKindOfClass:[UIScrollView class]]) {
view.scrollEnabled = NO;
}
}
I'd look into this UIGestureRecognizerDelegate method:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
Here you can "kill" the page view controller's gesture recognizer by disabling and re-enabling it:
if (/* otherGestureRecognizer is page view controller's */) {
otherGestureRecognizer.enabled = NO;
otherGestureRecognizer.enabled = YES;
}
So I have a homepage view that people see when they first boot up the app, it has several different options. Yesterday I added a tutorial overlay, so the first time they open the app I have a view that is 0.5 alpha black and is fullscreen over the other view, this view has white text and arrows pointing to functions on the page. I attached a tap gesture recognizer to this view and its action is to call the next tutorial screen ( 3 in total). Afterwords they all are hidden and the app acts as normal. This all works, except even though my view is full screen, with User Interaction Enabled checked and a gesture tap recognizer, the gestures / touches on the sub view still work. So if I just tap some white space on the app the tutorial and tap gesture work as expected, cycle me through the pages etc and works. However if I accidentally press a sub view button or do a gesture from the subview it will do the action (take you to a new page or w/e)
So basically as far as I can tell my view despite being on top of the other and having a tap gesture recognizer attached to the view the sub views are still getting pressed, any ideas?
Check the tap event view before doing any operation..
- (IBAction)yourTapEvent:(UITapGestureRecognizer *)gestureRecognizer
{
UIView *piece = [gestureRecognizer view];
if(piece == (view on which you have added gesture))
{
//Do your necessary operation
}
}
try this it would help you to disable gesture on its subviews
- (void)tapAction:(UITapGestureRecognizer *) gestureRecognizer{
UIView *v = [gestureRecognizer view];// Guesture added view
NSArray *temp = [self.view subviews];
for (int i = 0; i<temp.count; i++) {
if([temp objectAtIndex:i]== v){
// Do your swipe tap action here
}
}
}
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?
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;
}
}