我想模仿 UIScrollView 的行为,当您拖动 scrollView 时,当前线程 RunLoop 模式更改为 UITrackingRunLoopMode,当您停止拖动时返回 NSDefaultRunLoopMode。
不过,我想用我自己的类来做,拖拽 View ...现在我正在使用这段代码
while (_draggingView && [[NSRunLoop currentRunLoop] runMode:UITrackingRunLoopMode beforeDate:[NSDate distantFuture]]);
当我停止拖动时,_draggingView 变为 nil,因此我停止在该模式下循环。有没有更优雅/更好的方法来做到这一点?
UIScrollView 是怎么做到的?输入源?
谢谢
最佳答案
您可以使用 CFRunLoopStop
强制运行循环返回。
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
CFRunLoopStop(CFRunLoopGetMain());
}
关于ios - 在我决定停止它之前,将当前线程 NSRunLoop 设置为以某种模式运行的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10727306/