Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct way of setting the current thread NSRunLoop to run in a certain mode until I decide to stop it?

I want to mimic the UIScrollView behavior where the current thread RunLoop mode changes to UITrackingRunLoopMode when you drag the scrollView, and back to NSDefaultRunLoopMode when you stop dragging.

I want to do it with my own class, though, dragging around views... Right now I'm using this code

while (_draggingView && [[NSRunLoop currentRunLoop] runMode:UITrackingRunLoopMode beforeDate:[NSDate distantFuture]]);

When I stop dragging, _draggingView changes to nil so I stop looping in that mode. Is there a more elegant/better way of doing this?

How is UIScrollView doing it? Input sources?

Thank you

like image 299
LocoMike Avatar asked May 23 '12 20:05

LocoMike


1 Answers

You can use CFRunLoopStop to force a run loop to return.

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesEnded:touches withEvent:event];
    CFRunLoopStop(CFRunLoopGetMain());
}
like image 141
rob mayoff Avatar answered Oct 21 '22 14:10

rob mayoff