UIScrollView freezes after using SetContentOffset or scrollRectToVisible - iphone

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.

Related

How To Make Scroll View Scroll Even If A Button Subview Is Pressed

There are countless questions about UIScrollViews, touch events and subviews, but I couldn't find one that solved my dilemma. I have a UIScrollView with delayed and cancellable content touches in which I have added UIButtons. I can scroll the view wherever I touch (including the buttons), but if my finger lingers on a button for too long, it registers as touching the button, as I want and is expected. However, if I then move my finger as if trying to scroll, the scroll view does not scroll - how can I make it do so? The basic effect I am trying to achieve is like a UITableView handles touches for the cells.
Thanks for your help.
Try implementing the following in your UIScrollView subclass:
- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
return YES;
}

Why does touchesBegan stop working when UIImageView in placed inside a UIScrollView?

UIView -> UIImageView
I know I have things somewhat working ok since I can tap on my UIImageView and see an NSLog() statement in my touchesBegan method.
.
UIView -> UIScrollView -> UIImageView
I drag that same UIImageView into a UIScrollView and touchesBegan no longer gets called when I tap on my UIImageView. (I haven't changed anything else. All the same connections, methods, and code remains unchanged.)
Why does touchesBegan no longer work? And what can I do to get it working again?
Add uitapgesture to get event
Code is
UITapGestureRecognizer *ges11=[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(Handeltap:)];
[imagename addGestureRecognizer:ges11];
Create one action name "Handeltap" U will get called there.
by default UIImageView don't handle user gestures.
set UIImageView instance's userInteractionEnabled to YES
Have a look at the documentation for UIScrollView.
Because a scroll view has no scroll bars, it must know whether a touch signals an intent to scroll versus an intent to track a subview in the content. To make this determination, it temporarily intercepts a touch-down event by starting a timer and, before the timer fires, seeing if the touching finger makes any movement. If the timer fires without a significant change in position, the scroll view sends tracking events to the touched subview of the content view. If the user then drags their finger far enough before the timer elapses, the scroll view cancels any tracking in the subview and performs the scrolling itself. Subclasses can override the touchesShouldBegin:withEvent:inContentView:, pagingEnabled, and touchesShouldCancelInContentView: methods (which are called by the scroll view) to affect how the scroll view handles scrolling gestures.
I'd also recommend reading the Scroll View Programming Guide.

How to redraw view while scrolling?

I have a UIScrollView. This scroll view scrolls my custom GameView. When I send setNeedsDisplay to my GameView, it redraws and everything goes fine.
Except when I'm in the middle of scrolling GameView. It does not redraw until the scrolling has stopped.
Is there any way to circumvent this and just force the view during the scroll?
By the way, I already found these questions, but they didn't help:
UIScrollView pauses NSTimer until scrolling finishes
How do I get my UIView to redraw while the user is scrolling a UIScrollView
Try sending the view's layer displayIfNeeded immediately after setNeedsDisplay.

Picker in a ScrollView doesn't scroll

I have a UIScrollView, inside it, a small UIView containing a UIPickerView.
I'm able to scroll the view up and down but whenever I try to scroll the picker, it scrolls the view instead. I can change the picker's value by clicking it but not scrolling.
Any ideas?
EDIT: I just tried scrollView.canCancelContentTouches = NO; but it only works when I first Touch and then Drag, as in the TouchesBegan event. The scrollView still scrolls if I touch-move the Picker as in the TouchesMoved event.
What can I do to give my Picker its natural behavior in a ScrollView?
You've already got canCancelContentTouches set to NO, but try setting delaysContentTouches to NO as well.

Scroll view touch detection

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