Restricting the right scroll for scroll view at some conditions - ios

I was working with scroll view with ten pages, user can scroll in both directions with gesture and button actions. But there are some situations in which a toggle button in view is on we need to stop right side scrolling up to user fills the data once he fills the data scrollview need to start scrolling again. one more situation is when toggle is on user need to skip all views and directly scroll to last view. I need to maintain page count on screen too.

Related

UIKit collection view, strange behavior (accessing/scrolling cells)

So I recently implemented a collection view in my app, and I got a bug that I can't seem to solve, searched it and saw no threads about it.
If I have my cursor/finger over the cells i can't scroll through my collection view i need select a "empty" area to scroll.
Second strange Behavior I came across is that I can't directly touch a cell. I need some sort of swipe gesture over it to trigger the code when a cell is selected.
If I go to my collection view on my storyboard and select Delays Content Touches and Cancellable Content Touches in the scrollview section, the collection view scrolls just fine but if I put my finger/cursor over a cell with these option enabled I can't access any cells anymore.
This completely confuses me.
and thank you for reading/considering this thread.
Let's see what your two properties do.
delaysContentTouches: If the value of this property is true, the scroll view delays handling the touch-down gesture until it can determine if scrolling is the intent. If the value is false , the scroll view immediately calls touchesShouldBegin(_:with:in:). The default value is true.
canCancelContentTouches: If the value of this property is true and a view in the content has begun tracking a finger touching it, and if the user drags the finger enough to initiate a scroll, the view receives a touchesCancelled(_:with:) message and the scroll view handles the touch as a scroll. If the value of this property is false, the scroll view does not scroll regardless of finger movement once the content view starts tracking.
First, you set delaysContentTouches to false. So the scrollview immediately calls the content view's touch handling methods, allowing it to handle the touch. Obviously, the scroll view won't start scrolling right away because of this, even if you drag.
Second, you also set canCancelContentTouches to false. But if the scroll view isn't allowed to "take over" touches that the content already handles (by cancelling them), it is never able to start scrolling later on either. So if your touch hits a content view, there is no possible way for the scroll view to start scrolling: it isn't allowed to scroll right away because it isn't allowed to delay the content touches, and it can't start scrolling later because it can't cancel the content touches.
I don't know what happens within your cells, not sure what code you put in there. However, you should probably allow your tableview to both delay touches (that means that your cell won't handle swipes that are cancelled immediately anyway because they were intended to be scroll gestures), and to cancel content touches (that means that when you touch down and don't release, you can still start a scroll gesture after a cell became highlighted).
i had the same problem when touching a cell, the problem was that I'm using more than one UIGesture without adding ".cancelsTouchesInView = false" for each one
so if you're using a UIGesture just add Your_Gesture.cancelsTouchesInView = false
and you should be able to access your cells

cross scrolling: tableview inside UIpageViewcontroller does not behave properly

In my app, I have a UIPageViewcontroller. Inside the UIPageViewcontroller, I have a Viewcontroller with a table inside of it.
The problem I am having is, when I am scrolling down the table, I can't scroll between pages. unless I lift my finger up. (this also has to make sure that table stops scrolling completely)
I was hoping there would be a more natural way of doing this.
Is there a way to swipe between pages even when your scrolling down the table, without have to lift up your finger
I just tried Instagram, they have same UI as you are trying to achieve.
When I scrolled through Insta posts, I could not Swipe between View Controllers until table scroll stops.
1 option you can do is to reduce the speed of table scroll using following code:
self.tableview.scrollView.decelerationRate = UIScrollViewDecelerationRateFast;
This code will allow table to stop quickly and hence user can swipe.
Hence, I would say, it is not possible to swipe between view controller unless table scrolling is stopped.

UIScrollView that can scroll, but not from user interaction

I want to have a scrollview that has 2 views on it. Both views fill up the screen, and when you push a button on one view it uses scrollRectToVisible to move to the other view.
I want the user to not be able to scroll it with their touch though, so disabling scrolling doesn't work. Obviously i could have scroll become re-enabled when the user touches the button than lock it again afterwards, but then the user could grab or interact while it's unlocked in the scroll animation.
Any ideas?
Woops. As it turns out, against some/lots of logic, you can actually disable scroll on the scrollview, but scrollRectToVisible still works, it'll only stop it working if you disable user interaction - i'me guessing because the view with the button inherits from the scollview, so the button wasn't actually working at all.

How to enable UIPageViewController's page scroll while scrolling its content vertically (a collection view)?

I'm making an app like SmartNews, with a UIPageViewController that contains many UICollectionView pages.
The structure:
A UIPageViewController, with pages scrolling horizontally. (Transition style is UIPageViewControllerTransitionStyleScroll)
Each page in it contains a UICollectionView scrolling a set of cells vertically.
Both view have the same size and touch areas on the screen are common.
The problem:
While the collection view is scrolling down by itself (i.e. the user is no longer touching the screen but the collection view is still scrolling by decelerating), the user can't swipe pages.
It seems if another pan gesture occurs at this moment, it is tracked by the collection view to stop the current scroll and it doesn't allow the user to swipe the page view controller.
Is there a way to allow the user to scroll pages (horizontally), while the collection view is still scrolling (vertically)?
(Instagram's search view realizes this feature.)
Thanks!
Found what I wanted to do here:
Cross Directional UIScrollViews - Can I Modify the Scrolling Behaviour?
I guess it's unsafe to do the same with UIPageController as the scroll view inside it is undocumented.
I will try to replace the UIPageController with a UISCrollView with paging enabled.

UIScrollView of buttons - TouchUpInside?

I have a UIScrollView filled with buttons that I created programatically.
Paging is enabled and whenever users scroll through the pages rapidly they always end up accidentally clicking buttons that they didn't mean to... Should I be using TouchUpInside or is this the reason for my problem?
One thing I've noticed is that if a user presses the button then slides the scrollview doesn't move but if they slide the scroll view very quickly and let go half way through the scroll and they grabbed the scrollview on the button then the button will become "pressed" is there any way I can have the buttons not do anything if they are clicked while scrolling is in progress or is the solution simpler than that (i.e. just changing the touch event to a different listener)
This did the trick!
setExclusiveTouch:YES

Resources