美文网首页iOS 开发每天分享优质文章
iOS开发(Swift)——时间器(Timer)的使用

iOS开发(Swift)——时间器(Timer)的使用

作者: 小七编程 | 来源:发表于2020-12-10 14:48 被阅读0次

全局变量的定义:var timer : Timer!

使用:timer=Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(self.textfieldNotification), userInfo: nil, repeats: true)
textfieldNotification是timer的方法名

销毁:如果像OC一样直接timer.invalidate()会崩溃,要用
guard let timer1 = self.timer
else{ return }
timer1.invalidate()

收录:https://blog.csdn.net/liumude123/article/details/54571895

相关文章

网友评论

    本文标题:iOS开发(Swift)——时间器(Timer)的使用

    本文链接:https://www.haomeiwen.com/subject/tuxrgktx.html