UIScrollView start scrolling threshold - swift

I'm looking for a way of 'sticking' a UIScrollView to it's position unless the touch has been moved by a certain threshold, at which point it will jump to where it should have scrolled to and continue scrolling.
The reason for this is that I have a vertical scroll and each cell inside the UIScrollView has a horizontal scroll. So I'd like to introduce a slight 'stickyness' to make sure the user doesn't accidentally scroll vertically when they mean to scroll horizontally.
I started by hijacking the contentOffset property in scrollViewDidScroll. The trouble with that is I cannot find out how much the scrollView would have moved by if I were setting the contentOffset
If I try to add a UIPanGestureRecognizer to the class then it overrides the UIScrollView and the UIScrollView becomes unresponsive.
Does anyone know a way to do this?
EDIT: edits based on comments.

Related

Swift ScrollView what gesture is called when scrolling is ended if the contentSize is equal to the frameSize?

I can't figure out a solution. I have a UIScrollView, and on each scroll towards right, I will increase the contentSize of the scrollView and add a View at that place. The problem is I have managed to save the last content offset by delegation when scrollview start dragging but I don't understand which delegate method to use for measuring where the gesture stopped. If I use scrollViewDidEndDecelerating, will be called immediately after the scrollViewWillBeginDragging because the content is settled to the same size of the frame.
Does anybody have any solution on it?

Preventing ScrollView from scrolling in certain area?

I hope you can help me...
I have a scrollview (UIScrollview) that contains a contentView (UiView).
Inside the contentview I have a Horizontal slider. My problem is that if the user swipes just next to the slider, trying to hit the slider, the scrollview scrolls. I would like to enlarge the area of the slider if possible, or just disable scrolling for a certain part of the scroll view.
Is this possible, and if yes, how?
Thanks...
You need to look at the following properties for customizing the look of a scroll view:
indicatorStyle
scrollIndicatorInsets
Or if this isn't to your taste: You could subclass UIScrollView and when the custom slider receives touches, read them in transform them and call setContentOffset on the UIScrollView. In my opinion that seems like a big task for very little reward and I'd just stick with the default behaviour/look.

UIScrollView Updating contentSize Causes Scroll

I have a UIScrollView that has a single child view within it. If I set the contentSize of the UIScrollView immediately after creation, everything works as I expect and I get scrolling.
The challenge is the view within the UIScrollView is dynamically sized. The width is fixed, but the height is unknown at the time I set up the scrollview.
When I do a [scrollView setContentSize:CGRectMake(...)] after the inner view does it's thing, the scrollview updates to the proper size and scrolling works. So basic scrolling works fine.
However, the major problem is that when I setContentSize at a later point, the UIScrollView decides to scroll down(with animation) towards the end of the scrollview, which is not what I want, I want the scroll to stay at the top, and let the contents within the scrollview either get bigger or smaller, without changing the apparent scroll position.
What am I missing?
Why don't you also call [scrollview setContentOffset:CGPointMake(0,0)]; when you call the setContentSize?
To force UIScrollView to scroll only e.g. horizontally, I always set non-scrollable value for contentSize to 0, using:
CGSizeMake(contentSize.width, 0).

UIScrollView change pages after animation

Ok, I have a complicated scenario here. I have a scrollview which scrolls horizontally and contains tiles, 1 centered on the screen at a time with the user still able to see if there are more to the left or right by way of having the edges of the 2 views visible on either side. I am able to add the views programmatically to the scrollview and have paging work properly, so the user can swipe back and forth between them. Another requirement is to have an initial animation where the first view slides in, then is bounced off to the left by the second view. I accomplished this by using a series of UIView animations, and it works well.
Here is my problem: After the animation completes, you cannot scroll left to get to the first UIView that was created. I suspect that this is because it was animated out to the left of the content area of the scrollview. I have tried to increase the contentSize of the scrollview, but I still get the same behavior.Once the initial scrollview has been moved off to the left, I cannot swipe to page to it.
Is there a common pattern I could use to accomplish this in a better way?
It sounds to me like you're animating the child view's frame to the left so that the x coordinate of that first view's frame is negative, instead of animating the scroll view's contentOffset to the right. If that's the case, is there a reason you aren't just setting the scroll view's contentOffset inside an animation block? If there is a reason, what if after the animation completes you "fix up" the content offset and the frames of the child views so that none of the views are in a negative position.
But, I guess I have more questions than answers right now, so it might help to post the code showing how you do your animations to make it easier to answer your question.

Second UIScrollView responding when using a UIScrollView

This is more of a check as I believe this is right but its a lot of work if I'm wrong.
I want to basically achieve fixed positioning with a scrollView. I want to have a list along the top that is always visible, scrolls horizontal only and then a scrollview beneath that to move around the information which scrolls both vertically and horizontally.
I figure I need to subclass UIScrollView and overwrite touchesBegan, touchesMoved and touchesEnded to send the touch to both UIScrollViews.
Is this right or off track?
Cheers
Overriding the touch events on a scroll view is probably not what you want to do. Instead you can simply use a single scroll view, and then in the parent view's -layoutSubviews or in the scroll view's delegate methods you can move the list so it's always at the same vertical position (use the scroll view's contentOffset property to determine where that should be). Both the delegate method and -layoutSubviews is called before the drawing actually occurs after the scroll view scrolls, so by always repositioning your view where you want it to be, it will appear to remain fixed to the user.