How to prevent scrolling in UIScrollView when action is performed - ios

I'm using https://github.com/PaoloCuscela/Cards inside of a UIScrollView. When the card is opened, it's impossible to close because the whole view scrolls. Is there a way to disable scrolling while the card is opened and reenable when it's closed?

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

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 Show Scrollbar Always On UICollectionView

I have a UICollectionView added to a UIView in an app I am working on. Displayed in the UICollectionView I have a set of images pulled from Core Data. The vertical scrolling works fine but the scrollbar does not display until the user touches the UICollectionView.
How can I make sure the scrollbar at the right is always visible so that an indication is given to the user that it is scrollable?
You can't make them always visible. Instead, you can flash them once, when the user is first presented with the collection view to notify them, that this view can be scrolled.
Since UICollectionView is a subclass of UIScrollView you can do this:
[myCollectionView flashScrollIndicators];
Check out the Settings app for instance. When you go to a settings list that is longer then the screen, the scroll indicator is flashed once.
FYI for Swift:
myCollectionView.flashScrollIndicators()

UIScrollView: Pickup Scroll Mid-Swipe

I'm attempting to add a scrollview to the view and have its scroll initiated as soon as it hits with the finger already down on the screen. As of now I am clicking a button that makes the scrollview appear on top of it... this means I click, then have to lift my finger, then place it back down to begin scrolling.
Is there anyway to have the scrollview start scrolling even though the touch down has already occurred? Or to pass that touch saved from the button to the scrollview as soon as it appears so that it will drag? Or possibly fake the start of the touch altogether once the scrollview starts?

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