UIScrollView that can scroll, but not from user interaction - ios

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.

Related

How do I move my custom view with keyboard interactive hiding?

I have my tableview set to hide the keyboard interactively. This works beautifully. The user pulls down on my tableview and when the finger hits the keyboard, it moves down with the finger.
However I have a custom view for text entry that I would like to interactively move as the user drags down.
I tried using UIKeyboardDidChangeFrame, UIKeyboardWillHide, and UIKeyboardDidHide notifications, but they aren't called repeatedly as the keyboard is pulled down.
I can't just use the tableView scroll offset, because it depends on the contact point of the finger.
Any ideas?

How to prevent scrolling in UIScrollView when action is performed

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?

Scrollview with button(s) that can appear and disappear on tap

I have created a scrollview, to scroll through an array of images, and I have a button and soon to be 6 more on the screen. Now to make the photo nicer, I would simply like to make the buttons disappear and when tapped on again to appear.
Now I know how to do this with just a regular view with simple isHidden, and how to make it reappear when tapped on, but I am largely confused on how to do it on a scrollview because on a regular view, I just put a button over the whole screen but with the scrollview I can't. Any ideas anyone? Still getting better at this one step at a time, and one question at a time.
Here is a screenshot: http://imgur.com/a/Ll6QO
Use a gesture recognizer on the scrollview.
Add a touch gesture recognizer to toggle the visibility of your buttons. Be sure that the gesture recognizer doesn't cancel touches in view, otherwise you won't be able to scroll.

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 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