Disable horizontal swipe for UIPageViewController (except at edges) - ios

I essentially want a UITextView to scroll vertically but not ever be able to accidentally scroll the UIPageViewController when the gesture occurs within the UITextView.
I do still want the page turning gesture to work along the edges though:

Related

Is there a way to conform UIScrollView to custom swipes without changing to 2-finger swipes

I have scroll view with both horizontal and vertical scrolls (PDF View).
So I wanted to add diagonal swipe to that and figured out that after this:
scrollView?.panGestureRecognizer.require(toFail: swipe)
swipe works, but whole scroll view started reacting only to 2-finger gestures.
So it would be perfect for me to find a solution to remove this conflict of swipes.

Horizontal scroll in UIWebView and vertical scroll in UITableView

I have a UITableView with cells. One of the cells has a full size UIWebView.
On the web view I want ONLY to enable horizontal scroll (like coverflow).
I can do that with this ansawer: https://stackoverflow.com/a/12575036/406055
But: Then the UIWebView intercepts the vertical scroll (thus without performing it). I want the vertical scroll gesture to affect the tableview, not the web view.
The idea I have is to either overlay the web view with a UIView and add gesture recognizers and then pass the gesture on to the UIWebView only if it is horizontal.
But any other suggestions is welcome too.

Vertical UIScrollView over horizontal UIScrollView

iOS 8, Swift.
I'm trying to have a vertically scrolling view over a horizontally scrolling view. They're both UIScrollViews. The vertical scroll view is there to allow swiping up a view from the bottom. There is a spacer view on top using auto layout that is 1 pixel wide but the screens height.
This works fine until the underlying view is itself a scrollview to support horizontal scrolling.
I somehow need to pass the left/right pan gesture to the subview which is a UIScrollView.
Currently, the top level vertical scroll view is capturing all the gestures and not letting the underlying horizontal scroll view see the events.
I've tried various combinations of hitTest, gestureRecognizer delegate methods, scrollview subclassing but having come up with a nice clean solution.
I can use hitTest to pass events to the underlying horizontal scroll view when tapping the empty space at the top of the vertical scroll view, but then the vertical scroll view never processes a pan or swipe up to reveal the content that should appear on a swipe up.
Ideally, I'd like the top vertical scroll view to only handle pan up/down, and pass left/right pan to subview when the vertical scroll view is at the top.
Here's a brief method that may help you out:
Obj-C:
create scroll view that is invisible, and then pass the offset of the invisible scroll view or the touch events to the scroll views below depending on the offset of the touch events on the top invisible scroll view that covers the two underlying scroll views:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
[_verticalScrollView setContentOffset:CGPointMake(0, _insivibleScrollView.contentOffset.y)];
[_horizontalScrollView setContentOffset:CGPointMake(_insivibleScrollView.contentOffset.x, 0)];
}
You create an invisible scroll view, and by invisible, I mean you may have to keep the alpha value at like 0.01. You don't allow user interaction for the horizontal and vertical scroll views, but instead use the method above so that when the user touches the invisible scroll view you translate those touches to the scroll views below that are locked down to respond to only the offset of the invisible scroll view. As you've stated in your comment, there's probably more to this answer for your individual needs, but this is the basic "foundation" that will give you the effect that you probably want.
Swift:
Same method as above, but here's the function that you'll need:
func scrollViewDidScroll(scrollView: UIScrollView!) {
verticalScrollView.contentOffset = CGPointMake(0, invisibleScrollView.contentOffset.y)
horizontalScrollView.contentOffset = CGPointMake(invisibleScrollView.contentOffset.x, 0)
}

UIScrollView within UIScrollView within UIScrollView

I have a multidirectional UIScrollView within a horizontal UIScrollView within a vertical UIScrollView. When I reach the horizontal content limit of the innermost scrollView, the containing horizontal scrollview begins scrolling just as I want.
But when I reach the vertical content limit of the innermost scrollView, I do not get any action on the top level vertical scrollView.
If all vertical content is visible at innermost level (so no vertical scrolling is possible), then the top level vertical scrollview takes over fine. Any clues on how to fix this?
I get this same behavior with Apple "PhotoScroller" sample code if I embed their photo paging scrollView in a vertical scrollView. If the photo is not zoomed, then both the horizontal and vertical scrollviews will work. If the photo is zoomed but panning stops because it has hit the horizontal or vertical limit, then only the horizontal scrollview works.
This is using an older version of the sample code that implements the photo paging as a UIScrollView rather than UIPageViewController. With current UIPageViewController version, paging is not possible when the photo is zoomed.
To answer my own question, I used gestureRecognizerShouldBegin: delegate to determine whether the innermost scrollView was at a boundary when the pan gesture began. If so, I responded to shouldRecognizeSimultaneouslyWithGestureRecognizer:
delegate to enable the UIPanGestureRecognizer on both the inner scrollView and the vertical scrollView. This allowed a single gesture to scroll both simultaneously. Then, I over-rode setContentOffset on both scrollViews to suppress the scrolling on the wrong one.
I think a better answer is probably to replace the UIPanGestureRecognizer on the inner UIScrollView with a custom gesture recognizer that cancels itself when started at a boundary and dragging past the boundary. But, I could not get that to work.
Still not clear to me why the horizontal version of this just worked automatically. Perhaps there is some special case handling in the UIScrollViewPanGestureRecognizer to handle horizontal case, or interaction with immediate superView.

horizontal scrolling of a scrollView in a scrollView - small problem

i have a scrollView that fits the whole screen. In that View i show some UIImages that scroll horizontally. Like in the PageControl Project from Apple.
Then, when the user taps the screen, i fade in a scrollView at the bottom with some other images. Also horizontally scrolling. Like in the ScrollView Project from Apple.
My problem is, that when i come to the end of the scrollView which was faded in, the upper scrollView also starts to drag. How can i stop that during activation of the second scrollView?
Redraw the frame limits on your first scrollView when the second enters the screen. That way, your touches won't respond to both views. This means you need a container-view to keep both views seperated from each other.
Then you just rescale it back whenever your second scrollView disappears.
Edit: or disable scroll in your first scrollview while the second is open.

Resources