Hi.
Is there a way to stop the scrolling in a uiscrollview ?
I want to stop the scrollview when the user touches/drags a zoomslider. If I don't and the user drag the scrollview and then start zooming it jumps around like crazy.
Do you need the user to be able to zoom, or interact with the scrollview?
If not, you can set userInteractionEnabled to NO.
Yes, I need the user to be able to zoom & drag the scrollview, but as soon as he touches the slider I want the moving/zooming to stop and to set the zoomvalue from the slider by calling setZoomScale:slider.value.
I tried to set the scrollEnabled to NO when the user touches the slider and back to YES when the user release the slider, but the scrollEnabled doesn't seem to have any impact before the scrollview has stopped moving.
What about creating an IBAction that checks if the slider's value has changed, and if it is, set userInteractionEnable to NO, and when the user lifts the finger, set it back to YES?
sorry for misunderstand what you want
Now please try this
Code:
@implementation xUIScrollView
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *v = [self viewWithTag:999];
CGPoint convertedPoint = [self convertPoint:point toView:v];
// If the touch is inside the view, let the view handle it
if ([v pointInside:convertedPoint withEvent:event])
{
return v;
}
else
{
return [super hitTest:point withEvent:event];
}
}
@end
with your slider's tag is 999
with this the scroll view will not process your touch but release it to your slider
Good luck!
The slider is not in the scrollview so thats not the problem. I just want to send a call to the slideview so it stop scrolling instantly.
I tried to set userInteractionEnabled=NO when the user touches the slider, but that doesn't stop the scrolling.
Sorry for my bad explaining .
I had a similar situation where I needed to tell a UIScrollView to stop scrolling and had a crazy idea that seems to work. In my testing so far, the behavior seems identical to what happens when a user touches a view that is scrolling - it stops immediately. It also seems to handle bounces the same way - the view stops scrolling and immediately goes to the edge of the content.
Try the following code. If you wanted to, you could also extend the UIScrollView class and include this as a function:
//Stop the scrolling in a UIScrollView by telling the view to scroll to its current offset position
//(or to scroll to the edge of the view if the current offset position is outside of the content
//area due to a "bounce")
float x = fmin(fmax(minX, currentX), maxX);
float y = fmin(fmax(minY, currentY), maxY);
//Tell the view to scroll to the new position. Note that animated must be YES in order to stop
//any current scrolling animations.
[myScrollView setContentOffset:CGPointMake(x, y) animated:YES];
NOTE: In order to get the fmin and fmax functions to work, you will need to #import <math.h>
I had a similar situation where I needed to tell a UIScrollView to stop scrolling and had a crazy idea that seems to work. In my testing so far, the behavior seems identical to what happens when a user touches a view that is scrolling - it stops immediately. It also seems to handle bounces the same way - the view stops scrolling and immediately goes to the edge of the content.
Try the following code. If you wanted to, you could also extend the UIScrollView class and include this as a function:
//Stop the scrolling in a UIScrollView by telling the view to scroll to its current offset position
//(or to scroll to the edge of the view if the current offset position is outside of the content
//area due to a "bounce")
float x = fmin(fmax(minX, currentX), maxX);
float y = fmin(fmax(minY, currentY), maxY);
//Tell the view to scroll to the new position. Note that animated must be YES in order to stop
//any current scrolling animations.
[myScrollView setContentOffset:CGPointMake(x, y) animated:YES];
NOTE: In order to get the fmin and fmax functions to work, you will need to #import <math.h>
I just ran into a situation where I needed my tableview to stop scrolling in order to load another list of data to display...and this works like a charm.