Timer
@_spi(FW) extension Timer
-
创建Timer,使用target-action,自动CommonModes添加到当前的运行循环中,避免ScrollView滚动时不触发
Declaration
Swift
public static func fw_commonTimer(timeInterval: TimeInterval, target: Any, selector: Selector, userInfo: Any?, repeats: Bool) -> Timer
Parameters
timeInterval
时间
target
目标
selector
方法
userInfo
参数
repeats
是否重复
Return Value
定时器
-
创建Timer,使用block,自动CommonModes添加到当前的运行循环中,避免ScrollView滚动时不触发
Declaration
Swift
public static func fw_commonTimer(timeInterval: TimeInterval, block: @escaping (Timer) -> Void, repeats: Bool) -> Timer
Parameters
timeInterval
时间
block
代码块
repeats
是否重复
Return Value
定时器
-
创建倒计时定时器
Declaration
Swift
public static func fw_commonTimer(countDown: Int, block: @escaping (Int) -> Void) -> Timer
Parameters
countDown
倒计时时间
block
每秒执行block,为0时自动停止
Return Value
定时器,可手工停止
-
创建Timer,使用block,需要调用addTimer:forMode:安排到当前的运行循环中(CommonModes避免ScrollView滚动时不触发)。
示例:[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]
Declaration
Swift
public static func fw_timer(timeInterval: TimeInterval, block: @escaping (Timer) -> Void, repeats: Bool) -> Timer
Parameters
timeInterval
时间
block
代码块
repeats
是否重复
Return Value
定时器
-
创建Timer,使用block,默认模式安排到当前的运行循环中
Declaration
Swift
public static func fw_scheduledTimer(timeInterval: TimeInterval, block: @escaping (Timer) -> Void, repeats: Bool) -> Timer
Parameters
timeInterval
时间
block
代码块
repeats
是否重复
Return Value
定时器
-
暂停NSTimer
Declaration
Swift
public func fw_pauseTimer()
-
开始NSTimer
Declaration
Swift
public func fw_resumeTimer()
-
延迟delay秒后开始NSTimer
Declaration
Swift
public func fw_resumeTimer(afterDelay delay: TimeInterval)