Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-14-2009, 04:05 AM   #1 (permalink)
kae
Registered Member
 
Join Date: Sep 2008
Posts: 26
kae is on a distinguished road
Default Stop uiscrollview scrolling

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.
kae is offline   Reply With Quote
Old 10-14-2009, 04:11 AM   #2 (permalink)
iPhone Developer
 
kohjingyu's Avatar
 
Join Date: May 2009
Location: Singapore
Posts: 326
kohjingyu is on a distinguished road
Default

I think this will work:

Code:
scrollView.scrollable = NO;
Hope that helps.
__________________
Bacteria Bash
Cheese Collect
Jokestar
Follow me on Twitter for news about my apps:
(Website|Twitter)
kohjingyu is offline   Reply With Quote
Old 10-14-2009, 05:16 AM   #3 (permalink)
kae
Registered Member
 
Join Date: Sep 2008
Posts: 26
kae is on a distinguished road
Default

Quote:
Originally Posted by kohjingyu View Post
I think this will work:

Code:
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.
kae is offline   Reply With Quote
Old 10-14-2009, 05:21 AM   #4 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 18
ltgbau is on a distinguished road
Default

Quote:
Originally Posted by kae View Post
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
ltgbau is offline   Reply With Quote
Old 10-14-2009, 05:29 AM   #5 (permalink)
iPhone Developer
 
kohjingyu's Avatar
 
Join Date: May 2009
Location: Singapore
Posts: 326
kohjingyu is on a distinguished road
Default

Do you need the user to be able to zoom, or interact with the scrollview?

If not, you can set userInteractionEnabled to NO.
__________________
Bacteria Bash
Cheese Collect
Jokestar
Follow me on Twitter for news about my apps:
(Website|Twitter)
kohjingyu is offline   Reply With Quote
Old 10-14-2009, 05:55 AM   #6 (permalink)
kae
Registered Member
 
Join Date: Sep 2008
Posts: 26
kae is on a distinguished road
Default

Quote:
Originally Posted by kohjingyu View Post
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.
kae is offline   Reply With Quote
Old 10-14-2009, 06:13 AM   #7 (permalink)
iPhone Developer
 
kohjingyu's Avatar
 
Join Date: May 2009
Location: Singapore
Posts: 326
kohjingyu is on a distinguished road
Default

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?
__________________
Bacteria Bash
Cheese Collect
Jokestar
Follow me on Twitter for news about my apps:
(Website|Twitter)
kohjingyu is offline   Reply With Quote
Old 10-14-2009, 06:32 AM   #8 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 18
ltgbau is on a distinguished road
Default

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!
ltgbau is offline   Reply With Quote
Old 10-14-2009, 06:52 AM   #9 (permalink)
kae
Registered Member
 
Join Date: Sep 2008
Posts: 26
kae is on a distinguished road
Default

Quote:
Originally Posted by ltgbau View Post
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 .
kae is offline   Reply With Quote
Old 10-21-2009, 11:27 PM   #10 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 18
sbudhram is on a distinguished road
Default

Quote:
Originally Posted by ltgbau View Post
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!
LTGBAU, i just want to comment that I found that piece of code you posted invaluable. Thanks!
sbudhram is offline   Reply With Quote
Old 03-04-2010, 09:59 AM   #11 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 1
akeele is on a distinguished road
Default Solution

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>

Last edited by akeele; 03-04-2010 at 03:11 PM.
akeele is offline   Reply With Quote
Old 11-07-2010, 04:40 PM   #12 (permalink)
Developer
 
nobody's Avatar
 
Join Date: Jul 2009
Location: Los Angeles
Posts: 181
nobody is on a distinguished road
Default

Quote:
Originally Posted by akeele View Post
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!!
__________________
iPhone/iPod Touch Apps by Tiny Tech Studios



nobody is offline   Reply With Quote
Old 04-19-2011, 04:14 AM   #13 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 1
andreimarincas is on a distinguished road
Default

[self.myScrollView setContentOffset:self.myScrollView.contentOffset animated:NO];
andreimarincas is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 334
9 members and 325 guests
givensur, glenn_sayers, guusleijsten, ipodphone, mediaspree, mtl_tech_guy, Punkjumper, whitey99, yys
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,883
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:36 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0