RileyE
RileyE

Reputation: 11084

Stop UIScrollView scrolling during touch

Is there a way to stop a UIScrollView from scrolling while a touch is still held down? Setting the content offset using the scrollViewDidScroll: delegate method is excessive and can cause some issues (view moves and resets quickly) with the GPU, so I was hoping for a cleaner solution, if there is one.

Upvotes: 0

Views: 2182

Answers (2)

A R
A R

Reputation: 461

You can simply turn it out by using its property scrollEnabled in viewDidLoad..

self.myScrollView.scrollEnabled = NO;

Upvotes: 2

Chip Snyder
Chip Snyder

Reputation: 428

I would try:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [scrollView setScrollingEnabled:NO];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    [scrollView setScrollingEnabled:NO];
}

That will turn it off for a press and you can adjust detecting how far the "Move" was from the original touch to see if you want to reenable scrolling or not

Upvotes: 0

Related Questions