Prevent delegate method from being called too often

Posted by Lord Zsolt on Stack Overflow See other posts from Stack Overflow or by Lord Zsolt
Published on 2013-11-11T09:16:25Z Indexed on 2013/11/11 9:54 UTC
Read the original article Hit count: 190

Filed under:
|
|

How would you add a delay between certain method being called?

This is my code that I want to only trigger 30 times per second:

- (void) scrollViewDidScroll: (UIScrollView*)scrollView {
   [self performSelector:@selector(needsDisplay) withObject:nil afterDelay:0.033];
}

- (void) needsDisplay {
    [captureView setNeedsDisplay];
}

If I leave it like this, it only gets called after the user stopped scrolling.

What I want to do is call the method when the user is scrolling, but with a delay of 33 milliseconds between each call.

© Stack Overflow or respective owner

Related posts about ios

Related posts about objective-c