class JFThread : Thread {
// override func main() {
// print("JFThread main...")
//}
}
// VC 的一个Property
var myThread: JFThread?
override func viewDidLoad() {
super.viewDidLoad()
myThread = JFThread(target: self, selector: #selector(testThread), object: nil)
myThread!.start()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
//当点击屏幕的时候,会来到performSelector这个方法,而我们可以看到performSelector相当于是sourse
self.perform(#selector(touchMe), on: myThread!, with: nil, waitUntilDone: false)
}
func touchMe () {
print("toucheme \(Thread.current)")
}
func testThread() {
print("--testThread \(Thread.current)")
/* 1
RunLoop.current.add(Port(), forMode: .commonModes)
RunLoop.current.run() // Already Run 不执行
*/
/* 2
while true {
// Already Run 不执行
// 触摸也不执行
// 线程启动 没有添加Runloop需要的数据源 && Runloop 没启动
}
*/
/* 3
RunLoop.current.run()
// Already Run 执行
//触摸也不执行
// Runloop 启动后由于没有数据源 就立即退出了
*/
/* 4
while true {
RunLoop.current.run()
// 触摸事件有打印 Already Run 不执行
}
*/
print("Runloop already run")//
}
一个小测试-Runloop
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
相关阅读更多精彩内容
- 刚接触项目不久,最近产品说有一个点要优化,App的启动页面显示时间太长了。一直在开发其它的app,还真没注意这个点...
- 【蝴蝶效应】 蝴蝶效应:上个世纪70年代,美国一个名叫洛伦兹的气象学家在解释空气系统理论时说,亚马逊雨林一只蝴蝶...