Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

Stop uiscrollview scrolling

kaekae Posts: 28Registered Users @
edited April 2011 in iPhone SDK Development
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.
Post edited by kae on

Replies

  • kohjingyukohjingyu Posts: 326Registered Users
    edited October 2009
    I think this will work:
    scrollView.scrollable = NO;
    

    Hope that helps. :)
  • kaekae Posts: 28Registered Users @
    edited October 2009
    kohjingyu wrote: »
    I think this will work:
    scrollView.scrollable = NO;
    

    Hope that helps. :)

    I've tried this, but this doesn't stop the current scrolling like when you drag the view fast and then tap on it to stop.
  • ltgbaultgbau Posts: 18Registered Users
    edited October 2009
    kae wrote: »
    I've tried this, but this doesn't stop the current scrolling like when you drag the view fast and then tap on it to stop.
    I haven't try this yet but I think you can fake touch event
    App in AppStore:<br />
    <a href="http://appsfire.com/f2" target="_blank">Multi Protractor</a>
  • kohjingyukohjingyu Posts: 326Registered Users
    edited October 2009
    Do you need the user to be able to zoom, or interact with the scrollview?

    If not, you can set userInteractionEnabled to NO.
  • kaekae Posts: 28Registered Users @
    edited October 2009
    kohjingyu wrote: »
    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.
  • kohjingyukohjingyu Posts: 326Registered Users
    edited October 2009
    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?
  • ltgbaultgbau Posts: 18Registered Users
    edited October 2009
    sorry for misunderstand what you want :D
    Now please try this
    @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!
    App in AppStore:<br />
    <a href="http://appsfire.com/f2" target="_blank">Multi Protractor</a>
  • kaekae Posts: 28Registered Users @
    edited October 2009
    ltgbau wrote: »
    sorry for misunderstand what you want :D
    Now please try this
    @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 :).
  • sbudhramsbudhram Posts: 18Registered Users
    edited October 2009
    ltgbau wrote: »
    sorry for misunderstand what you want :D
    Now please try this
    @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!

    LTGBAU, i just want to comment that I found that piece of code you posted invaluable. Thanks!
  • akeeleakeele Posts: 1New Users
    edited March 2010
    Hi,

    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 currentX = myScrollView.contentOffset.x;
    float minX = 0;
    float maxX = fmax(0, myScrollView.contentSize.width - myScrollView.frame.size.width);

    float currentY = myScrollView.contentOffset.y;
    float minY = 0;
    float maxY = fmax(0, myScrollView.contentSize.height - myScrollView.frame.size.height);

    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>
  • nobodynobody Posts: 179Registered Users
    edited November 2010
    akeele wrote: »
    Hi,

    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 currentX = myScrollView.contentOffset.x;
    float minX = 0;
    float maxX = fmax(0, myScrollView.contentSize.width - myScrollView.frame.size.width);

    float currentY = myScrollView.contentOffset.y;
    float minY = 0;
    float maxY = fmax(0, myScrollView.contentSize.height - myScrollView.frame.size.height);

    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.

    Thanks!!
    <div align="center"><b>iPhone/iPod Touch Apps by Tiny Tech Studios</b><br />
    <br />
    <a href="http://www.tinytechstudios.com" target="_blank">5031188912_c8ab4cd97c.jpg</a> <br />
    </div><div align="center"><
  • andreimarincasandreimarincas Posts: 1New Users
    edited April 2011
    [self.myScrollView setContentOffset:self.myScrollView.contentOffset animated:NO]; ;)
Sign In or Register to comment.