swift3.0 Timer 定时器

前端之家收集整理的这篇文章主要介绍了swift3.0 Timer 定时器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

贡献者:赵大财
博客:https://my.oschina.net/zhaodacaiGitHub:https://github.com/zhaodacai
邮箱: zhaodacai@yeah.com QQ:327532817
=============================

var cycyleTimer : Timer?
    // 添加定时器
    fileprivate func addCycleTimer() {
        cycyleTimer = Timer(timeInterval: 2.0,target: self,selector: #selector(self.scrollToNext),userInfo: nil,repeats: true)
        RunLoop.main.add(cycyleTimer!,forMode:RunLoopMode.commonModes)
    }
    
    // 移除定时器
    fileprivate func removeCycleTimer() {
        // 从运行循环中移除
        cycyleTimer?.invalidate()
        cycyleTimer = nil
    }
    
    // 定时器的方法
    @objc fileprivate func scrollToNext() {
        //to do
    }
let displayLink = CADisplayLink(target: self,selector: #selector(update))
        displayLink.add(to: RunLoop.current,forMode: RunLoopMode.defaultRunLoopMode)
        displayLink.preferredFramesPerSecond = 1
        displayLink.isPaused = false
原文链接:https://www.f2er.com/swift/322605.html

猜你在找的Swift相关文章