ios – 设置当前线程NSRunLoop在一定模式下运行的正确方法是什么,直到我决定停止它?

我想模拟UIScrollView行为,当您拖动scrollView时,当前线程RunLoop模式更改为UITrackingRunLoopMode,并在停止拖动时返回到NSDefaultRunLoopMode.

我想用自己的课程来做,但是,拖动着看法…现在我正在使用这个代码

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 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...