NSTimer(FWBlock)
@interface NSTimer (FWBlock)
/**
创建NSTimer,使用target-action,自动CommonModes添加到当前的运行循环中,避免ScrollView滚动时不触发
@param seconds 时间
@param target 目标
@param selector 方法
@param userInfo 参数
@param repeats 是否重复
@return 定时器
*/
+ (NSTimer *)fw_commonTimerWithTimeInterval:(NSTimeInterval)seconds target:(id)target selector:(SEL)selector userInfo:(nullable id)userInfo repeats:(BOOL)repeats NS_REFINED_FOR_SWIFT;
/**
创建NSTimer,使用block,自动CommonModes添加到当前的运行循环中,避免ScrollView滚动时不触发
@param seconds 时间
@param block 代码块
@param repeats 是否重复
@return 定时器
*/
+ (NSTimer *)fw_commonTimerWithTimeInterval:(NSTimeInterval)seconds block:(void (^)(NSTimer *timer))block repeats:(BOOL)repeats NS_REFINED_FOR_SWIFT;
/**
创建倒计时定时器
@param seconds 倒计时描述
@param block 每秒执行block,为0时自动停止
@return 定时器,可手工停止
*/
+ (NSTimer *)fw_commonTimerWithCountDown:(NSInteger)seconds block:(void (^)(NSInteger countDown))block NS_REFINED_FOR_SWIFT;
/**
创建NSTimer,使用block,需要调用addTimer:forMode:安排到当前的运行循环中(CommonModes避免ScrollView滚动时不触发)。
@note 示例:[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]
@param seconds 时间
@param block 代码块
@param repeats 是否重复
@return 定时器
*/
+ (NSTimer *)fw_timerWithTimeInterval:(NSTimeInterval)seconds block:(void (^)(NSTimer *timer))block repeats:(BOOL)repeats NS_REFINED_FOR_SWIFT;
/**
创建NSTimer,使用block,默认模式安排到当前的运行循环中
@param seconds 时间
@param block 代码块
@param repeats 是否重复
@return 定时器
*/
+ (NSTimer *)fw_scheduledTimerWithTimeInterval:(NSTimeInterval)seconds block:(void (^)(NSTimer *timer))block repeats:(BOOL)repeats NS_REFINED_FOR_SWIFT;
/// 暂停NSTimer
- (void)fw_pauseTimer NS_REFINED_FOR_SWIFT;
/// 开始NSTimer
- (void)fw_resumeTimer NS_REFINED_FOR_SWIFT;
/// 延迟delay秒后开始NSTimer
- (void)fw_resumeTimerAfterDelay:(NSTimeInterval)delay NS_REFINED_FOR_SWIFT;
@end
Undocumented
-
创建NSTimer,使用target-action,自动CommonModes添加到当前的运行循环中,避免ScrollView滚动时不触发
Declaration
Objective-C
+ (nonnull NSTimer *)fw_commonTimerWithTimeInterval:(NSTimeInterval)seconds target:(nonnull id)target selector:(nonnull SEL)selector userInfo:(nullable id)userInfo repeats:(BOOL)repeats;
Parameters
seconds
时间
target
目标
selector
方法
userInfo
参数
repeats
是否重复
Return Value
定时器
-
创建NSTimer,使用block,自动CommonModes添加到当前的运行循环中,避免ScrollView滚动时不触发
Declaration
Objective-C
+ (nonnull NSTimer *) fw_commonTimerWithTimeInterval:(NSTimeInterval)seconds block:(nonnull void (^)( NSTimer *_Nonnull __strong))block repeats:(BOOL)repeats;
Parameters
seconds
时间
block
代码块
repeats
是否重复
Return Value
定时器
-
创建倒计时定时器
Declaration
Objective-C
+ (nonnull NSTimer *)fw_commonTimerWithCountDown:(NSInteger)seconds block:(nonnull void (^)(NSInteger)) block;
Parameters
seconds
倒计时描述
block
每秒执行block,为0时自动停止
Return Value
定时器,可手工停止
-
创建NSTimer,使用block,需要调用addTimer:forMode:安排到当前的运行循环中(CommonModes避免ScrollView滚动时不触发)。
Note
示例:[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]
Declaration
Objective-C
+ (nonnull NSTimer *) fw_timerWithTimeInterval:(NSTimeInterval)seconds block:(nonnull void (^)(NSTimer *_Nonnull __strong))block repeats:(BOOL)repeats;
Parameters
seconds
时间
block
代码块
repeats
是否重复
Return Value
定时器
-
创建NSTimer,使用block,默认模式安排到当前的运行循环中
Declaration
Objective-C
+ (nonnull NSTimer *) fw_scheduledTimerWithTimeInterval:(NSTimeInterval)seconds block:(nonnull void (^)( NSTimer *_Nonnull __strong))block repeats:(BOOL)repeats;
Parameters
seconds
时间
block
代码块
repeats
是否重复
Return Value
定时器
-
暂停NSTimer
Declaration
Objective-C
- (void)fw_pauseTimer;
-
开始NSTimer
Declaration
Objective-C
- (void)fw_resumeTimer;
-
延迟delay秒后开始NSTimer
Declaration
Objective-C
- (void)fw_resumeTimerAfterDelay:(NSTimeInterval)delay;