贡献者:赵大财
博客: GitHub: 邮箱: 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