I got a scroll view with a bunch of buttons, which I want to both touch and drag.
To choose if it's a touch or a drag (not drag of the scroll view, "physically" dragging the button), I check the pan gesture recognizer of the button to see how far away the drag would be, if it's over a threshold I snap the button into drag mode and, removing it from the scroll view and adding it to my view controller's view (at the same location, so looks like it's in the same place).
This all works kinda smooth, except when I want to scroll and the pan fires at the same time. I need a way for the pan gesture recognizer to choose, based on velocity, if the scroll view should scroll or the button should be dragged.
The question: Is there a way for a UIPanGestureRecognizer to tell a UIScrollView to continue scrolling and cancel itself?
Related
I have scroll view with both horizontal and vertical scrolls (PDF View).
So I wanted to add diagonal swipe to that and figured out that after this:
scrollView?.panGestureRecognizer.require(toFail: swipe)
swipe works, but whole scroll view started reacting only to 2-finger gestures.
So it would be perfect for me to find a solution to remove this conflict of swipes.
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.
I have a Main view(currently displayed view).
AnotherView is added as a subview to a scrollview.The initial position of this AnotherView has to be in such a way that the bottom of this another view appears on the top most portion of the MainView.
Now,when I drag the AnotherView's bottom portion downwards,AnotherView should get displayed as SLIDING from top to bottom with the speed I drag it.
When I stop dragging,the sliding also should halt.
If I release the dragging after half of the screen,the sliding should continue to bottom of the screen.
How could I achieve this ?
You should use UIPanGestureRecognizer.
AnotherView should be in front of main or put it to front in Pan recogniser's function on UIGestureRecognizerStateBegan.
If UIGestureRecognizerStateChanged change anotherView frame accordingly to this movement. You can get movement by [panRecognizer translationInView:self.view] which returns CGPoint. And check if Another view is already after half of the screen. If you pass half of the screen, just use animateWithDuration to finish movement on UIGestureRecognizerStateEnded.
So another view doesn't need to be inside scrollview.
As far as I understood, you want to make something similar to sliding out menu. http://www.raywenderlich.com/32054/how-to-create-a-slide-out-navigation-like-facebook-and-path
There you can find example how to use pan recognizer to slide view by dragging.
I created a "slide view" (a UIView subclass) which animates on screen by dragging it up. The animation and everything else related to the animation works perfectly fine. This question targets only the very first touch on the screen when the slide view itself will be initialized:
The slide view itself uses the UIPanGestureRecognizerto recognize touches. The thing is, my slide view will be initialized only at the time when the user touches down a UIButton. Parts of the slide view are initially locates on that button, so that when the user touches that button, the touch is also located inside the slide view's frame.
I only want to create the view at the time the touch occurs, because the view is pretty heavy. I don't want to waste resources cause often the button is not even used.
How can I make the slide view recognize that first touch that also initializes (and adds it as a subview to super) the slide view itself?
You can check this out for more details:
Gestures
Well and you can add both gesture pan as well as tap gesture. It will definitely work as tap is not the first action of the pan gesture. So no need to wait for tap gesture to fail.
In short you can add both gestures and handle them simply.
I have a UIScrollView with an button just outside the content area of the scrollView. The user has to scroll up and hold the spring effect which one finger and push the button with another finger. The problem is that the touch on the button is never detected.
Please see the illustration below
The scroll view in it's initial state. the orange area is the scrollView, the white area the button
The user is now scrolling and holding with one finger to overcome the spring effect of the UIScrollView, and want to click the button
Any suggestions?
Check this out:
UIScrollView blocks all touches while zooming or scrolling
Make sure you have multitouch set to YES on the scrollview and also don't have any subviews with exclusive touch enabled.