I'm having an inconsistent problem where sometimes I press on a button inside the scrollview. The scrollview catches the event and scrolls instead of the button getting the touch event.
Any idea how to solve this bizarre behavior.
Thanks
Don't move your finger while it's pressed down on the button. If you move your finger at all, the scrollview will cancel the touches sent to the button and process them itself. It must do this so that you can scroll by touching anywhere on the scrollview, not just an empty space.
Related
I want to forward event from button which in the scrollview to scrollview when the button touched down and dragged inside.
by Using button's "addTarget: action: forControlEvent" function, I can receive button down and drag event and also can move scrollview as I dragged.
But the problem is the scroll view doesn't react like origin scrollview's scroll. This means there is no accelerate animation when I finish dragging.
I'm looking for the method forwarding event to scrollView so that the scrollview can react as it dragged on itself even though the event from the button on the scrollview.
Is there anyone who knows this?
I have a UIScrollView with paging enabled and I want to be able to jump to pages further down the line rather then swiping through each one. I attempted to use both setContentOffset and scrollRectToVisible. They both scroll the view to the correct point but after scrolling animated or not the scrollview becomes frozen and unresponsive to any touches. I tried setting it to the first responder but it changed nothing. I have a button outside of the scroll view and it still functions fine after the setContentOffset. There are also buttons inside the scrollview and not only will the scrollview not respond to touch for dragging but the buttons will not recognize the touches either.
[mainScroll setContentOffset:CGPointMake(mainScroll.frame.size.width*4, 0.0) animated:YES];
tldr; I can scroll through the view fine, through all the pages but when I try and call a setContentOffset or a scrollRectToVisible I get 'frozen' after the move.
I figured it out, stupid mistake.
In my scrollViewDidScroll I had:
scrollView.userInteractionEnabled=NO;
and in my scrollViewDidEndDecelerating
scrollView.userInteractionEnabled=YES;
and in scrollViewDidEndDragging:willDecelerate
if(!decelerate){scrollView.userInteractionEnabled=YES;}
I had this to prevent button presses and any random things during a page transition. But when setContentOffset is called it only causes scrollViewDidScroll to be called and neither of the other two, so the UserInteraction was never set back to Enabled, but only when using setContentOffset.
Simple fix.
i want to do a custom toolbar, something like the slide to unlock of android phones. In idle state, the user can see a button of the bottom left of the page. the user would then tap it, drag towards the right. When the user reaches the right end, the toolbar will then 'lock'. Buttons would be located at the toolbar.
I'm think of using a customview and touchmoved functions, but what I don't know how is how to make the view move with the touch, and how to actually lock the bar.
Everytime you move your finger the touchmoved function is called. In the touchmoved function you have to redraw the whole view or just set a new frame for this view. It pretty simple as you already know how to detect touches and react on them.
I've got a UIScrollView in my UIView. I've added some UIButtons to the scroll view.
If I touch down not on a button and drag, the scroll view drags fine.
If I touch down on a button and drag then the scroll view doesn't move.
I want the scroll view to always scroll around if dragged and the buttons only get selected on the Touch Up Inside event.
I don't want to check "Delay Content Touches" because I don't want to have to wait for the delay.
Does anyone know what I need to do to get this to work?
Regards,
Rich
Perhaps just outdated, but Redent84's answer is plain wrong.
You can solve this by adding:
scrollView.canCancelContentTouches = YES;
There's no automatic way of doing that. You have to manually handle the touch event, and then determine what the user wants to do, if he moves the finger X pixels up or down, then he wants to scroll, and if he releases the touch inside the button, then he probably wants to activate that action.
Regards!
I have a problem in the touchesMoved handler with a view that is added onto a UIScrollView. I add a number of labels to the scroll view. Each of these labels contain some text and, on swiping my finger on the labels, I have to play a specific file for that text.
If I just add the view onto the window directly, I get all of the touch events in touchesMoved without any problem. When I add my view onto the UIScrollView and then add this to the window, there is some lag in the touchesMoved handler. I am not getting continuous touch points in touchesMoved as with the normal view. As a result, while swiping the finger from the view, it happens that some labels are missed.
Is the problem due to scroll view? The same code runs perfectly in normal conditions (without a scroll view).
Does anyone have any solution to this?
UIScrollView sets a timer on touchDown to be able to know if it should handle scrolling or if it should pass the events on to subviews.
There is a property on UIScrollView for controlling this behaviour:
#property(nonatomic) BOOL delaysContentTouches