ZYGCDTimer 主要用于替代 NSTimer,不会强持有 target,基于 MSWeakTimer 进行修改的,本质上是个 GCD 定时器。
- 弱引用
target -
target销毁之后,自动调用invalidate - 支持
block创建定时器 - 支持设置
GCD queue - 支持暂停定时器
下载 demo 直接运行即可
- iOS 8.0+
- macOS 10.12+
ZYGCDTimer 支持 CocoaPods 安装。在 Podfile 中写入以下文本,然后执行 pod install 即可:
pod "ZYGCDTimer"使用 target-selector 创建定时器
+ (instancetype)timerWithTimeInterval:(NSTimeInterval)interval
target:(id)aTarget
selector:(SEL)aSelector
userInfo:(nullable id)userInfo
repeats:(BOOL)repeats
dispatchQueue:(dispatch_queue_t)dispatchQueue;使用 block 创建定时器
+ (instancetype)timerWithTimeInterval:(NSTimeInterval)interval
userInfo:(nullable id)userInfo
repeats:(BOOL)repeats
dispatchQueue:(dispatch_queue_t)dispatchQueue
block:(void (^)(ZYGCDTimer *timer))block;启用定时器
- (void)fire;无效定时器
- (void)invalidate;暂停定时器
- (void)pause;ripperhe, ripperhe@qq.com
ZYGCDTimer is available under the MIT license. See the LICENSE file for more info.
