ios move touch event between two uiscrollview - ios

I'm building an iOS layout which consists of a UITableView and a UIScrollView. The UIScrollView is inside a table cell of the UITableView and can be scrolled both horizontally and vertically. The diagram below shows this situation. If the user begins scrolling down/up on the UIScrollView the scrolling event should trigger setContentOffset of the table view, and not setContentOffset for the scroll view while the top of the scroll view will be on the dotted line (it's constant height). Then a scrolling touch event should trigger setContentOffset for the scroll view, not for the table view.
In another case: When the user starts scrolling on the table view, it should trigger setContentOffset for the table view, until the scroll view reaches the dotted line. Then the scroll view should handle setContentOffset.
My problem is how to transfer touch events between the table view and the scroll view during one sliding action.

This sounds like one of those cases where you want something quite specific and custom. So trying to do something clever with the gesture recognizers won't be enough.
The main problem is that the ways you can control gesture recognizers such as with gestureRecognizer:shouldReceiveTouch: and gestureRecognizerShouldBegin: only affect the start of the gesture (or for new touches, not ongoing ones), but you want a single ongoing gesture to transition between controlling each view. So for this reason I think you will need to place a large transparent view over your entire screen with a pan gesture recognizer on it and in your handlePan method decide which view you want to adjust and then call setContentOffset directly on that view. You can use the translation of the pan recognizer and the existing content offset to calculate the new one. I know this isn't very elegant, but I can't think of another way to achieve the effect you want.

I'm not sure if this is going to work, but you could try doing something like this:
Option
self.scrollView.panGestureRecognizer = self.tableView.panGestureRecognizer;
Option
[self.scrollView addGestureRecognizer:self.tableView.panGestureRecognizer];
Option
[self.tableView.panGestureRecognizer requireGestureRecognizerToFail:self.scrollView.panGestureRecognizer];

Related

Which the better way to make carousel view in swift with open - animation (expanding)?

I need to make carousel view in swift with "opening-animation".
First of all, I have created scroll view, after that have created subViews with my customView, maked my scrollView paged-enabled, and it's okay, but I need to make it expanding by swipe gesture. I added animation, but this view can't be higher than scrollView height, so I need to make this width and height (after gesture) like viewController's view height and width. And, it's the problem.
What's better way to do this?
Example screen:
BeforeGesture
Second example screen: after up-swipe gesture
I think you will need to handle it using the UIPanGestureRecognizer gesture which will give you the better control on all the different states of pan (drag began, drag ended). In your drag ended state you can handle the logic of increasing the height of scrollview and after that add the animation to show the expanded view with animation effect.
Let me know if you need any further help.

Is it possible to drive a table/collection view's scrolling from gestures inside another view?

Suppose there are two UIVIew subclasses in two different regions of the screen.
The first UIView subclass is a table or collectionView
The second view is a simple UIView.
Is it possible for gestures inside the second view to be "carried over" to the first view so that for example, a swipe up gesture in the second view would make the table/collection view scroll up ?
In WWDC 2012 Session 223: Enhancing User Experience with Scroll Views, Apple engineers explained that you can take a scroll view's panGestureRecognizer and add it to a different view to make that other view control the scroll view's scrolling.
Note that UITableView and UICollectionView are subclasses of UIScrollView.
So if you can put your table view and your second view into a common superview, you can move the table view's panGestureRecognizer to the superview and it will detect touches on both subviews.
[commonSuperview addGestureRecognizer:tableView.panGestureRecognizer];
The best way to achieve that is to encapsulate your 2 views in a another view and to add the GestureRecognizer on the motherView.
This way when the gesture triggers, with the location of the touch you can figure out if it started in one view or the other and you can track the move all the way to the second view.

Collection view not scrolling when interacting on a cell

My collection view controller is not responding when swiping on a cell(touch begin in a point on the cell). But it interacts when swipe began a point such as spaces between the cells.
It was previously scrolling vertically, not touch gestures(there was once but i deleted it and nothing really changed) and recognizers in collection view and cell. The interesting part is collection view's didSelectCellAtRow works perfectly fine when interact on cell but not responsive to scrolls.
You can only scroll when swiping from the spaces between the cells or any point in collection view that is not containing cell.
Any thoughts?
Are you sure the touch-down event is passed to the table view (scroll view) correctly?
Make sure the cells don't have a custom touch-down event (e.g. tap gesture recognizer, or touchesBegan method without calling the super inside) and also make sure the collection view delays content touches, it's a common mistake to uncheck it and forget it, and then try to understand why a view is not handling touches properly, but its children are.

Gesture Recognizer on sub-view outside view's bounds

I'm not sure if this is possible, but I have a view that is able to be dragged around the screen via pan gestures. Once the view is selected, little grippers appear on the corners of the view that allow the user to resize the view. The problem is, those grippers go outside the bounds of the view (they still show up, because clipSubviews is off), but gesture recognizers on those grippers are not firing when selecting the part of them that is drawn outside of the view. Making the view bigger to actually hold the grippers would break a lot of already created logic that is based on the size of the view, so that is a last resort for me.
Is there any other way to get gesture recognizers to work on views that are drawn outside of their parent view?
You could try overriding hitTest:withEvent: in a UIView subclass, and return the gripper view.

Zooming and moving a UIScrollView at the same time

I have a UIScrollView that takes up a portion of the screen, and its basic functions (scrolling and zooming) work just fine. For example, I can grab the scrollview with two fingers, and scroll left and right, while zooming in or out on the content.
I want to add the ability to move the UIScrollView up and down at the same time. Please note that I do not want to move the content of the scroll view, but the scroll view itself.
I have attempted to add a UIPinchGestureRecognizer to the UIScrollView which has allowed me to grab and move the scroll view, but I then lose the zoom and scrolling. It seems that adding a gesture recognizer makes all of the default actions stop (also, when I call setZoomScale, I get an EXC_BAD_ACCESS).
I've also considered checking touches, but touches on the UIScrollView aren't registered with the main view so I can't change its location using those values.
Does anyone have any suggestions on how this might be accomplished?

Resources