您的位置:首页 > 移动开发 > Swift

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

2017-01-16 10:43 453 查看
iOS开发交流群:301058503

全局变量的定义: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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息