Horizontal uitableview with screen edge swipe gesture - ios

I have a view which looks like this:
I implemented this view with two horizontal uitableview. So all promotions under certain category actually is in a table view which allow user to swipe left and right to change category. On the left top there is a button which opens a side view. Now I want to add a screen edge gesture to open the side view but it seems the screen edge gesture conflicts with the table view scrolling gesture.
So where should I do if I want to implement the screen edge gesture without disabling tableview's scroll gesture?
Thanks!

Set your gesture delegate in your viewcontroller class, and use this delegate method :
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES ;
}

Related

Fire UIPanGestureRecognizer with an outside starting point

I have a layout like the image below:
The black area is a camera, the red area is just an UIView with a UIPanGestureRecognizer and the green area a UICollectionView with images.
Right now, if the user presses the red area and starts dragging all the layout is moved to top and the user is able to see more items in the collection view at once while the camera overflows the device screen. All the logic is already done.
My problem is that I want the same functionality even if the user starts dragging outside of the red area, i.e. the user starts dragging the collection view from the bottom of the device so more items are shown, but if the user reaches (crosses, moves over) the red area, then the PanGestureRecognizer should get fired. Instagram has this functionality when selecting an image from disk. Is there a way to achieve this that I am missing? I tried overriding the red view with pointInside, touchesBegan and touchesMoved, but any of those get called if the drag comes from the collection view. SwipeGesture doesn't work either. Thanks!
You could try the following:
1) Add your PanGesture (the red one) that you want activated to the collection view too:
[self.collectionView addGestureRecognizer:redPanGesture];
2) In the method that gets called when the PanGesture is activated, filter it so that the logic gets executed only when the finger is on top of the red area:
CGPoint location = [recognizer locationInView:self.redView];
if(location.y > self.redView.frame.size.height)
{
[(UIPanGestureRecognizer *)recognizer setTranslation:CGPointZero inView:self.view];
return;
}
3) Set your class as the PanGesture's delegate:
redPanGesture.delegate = self;
4) Implement the method below, otherwise the collection view will not scroll:
- (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;
}
}

How to conditionally "pass through" a gesture from a UIButton to a UIScrollView?

I have a long, horizontal, narrow UIScrollView containing several buttons side-by-side. When a user drags a button vertically, a specific method is triggered (via a UIPanGestureRecognizer), and the scrollview doesn't scroll (even if his/her drag begins to go left or right). This is all good.
When a user drags horizontally anywhere on the scrollview, including directly on a button, the UIPanGestureRecognizer ignores the effect and the scrollview should scroll. It's the last effect I'm having trouble with: when the user horizontally drags directly on a button, the scrollview doesn't scroll. How can I "pass through" that horizontal gesture to the scrollview?
Thanks for reading!
Add this method to your buttons' UIPanGestureRecognizer's delegate:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return (otherGestureRecognizer == _scrollView.panGestureRecognizer);
}
On UIScrollView you can override
- (BOOL)touchesShouldCancelInContentView:(UIView *)view
Subclass UIScrollView (or UITableView) and return YES. It will cancel any touch from subviews when scrolling starts.
Give a thought to UILongPressGestureRecognizer. This might help you: Combine longpress gesture and drag gesture together

enable swipe on view controller, but disable within a view in that VC

I have a UIViewController where I have 2 UISwipeGestureRecognizers handling undo and redo (swipe right to undo, swiple left to redo). Within this VC I also have a UIView that is tracking touch began/moved/ended to change colors on another UIView. BTW, the undo/redo has to do with the color changes.
The problem I'm running into is that when I'm doing the touch events in the color changer view, they are sometimes interpreted as a swipe and undo/redo are happening.
How can I disable the swipe gestures just for the UIView in question but retain the ability to perform swipes on other areas of the VC?
Make the view controller a delegate of the gesture recognizer, then implement this delegate method:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
return touch.view != self.mySubviewToExclude;
}

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