测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布最后发布 | 2015 年 9 月 |
由 Brendan Conron、Rudd Fawcett 维护。
BZYStrokeTimer
是基于 CAShapeLayer
构建的出色且简洁的计时器。
您还可以根据需要暂停和恢复计时器。
要运行示例项目,请克隆仓库,并首先从 Example 目录运行 pod install
。
BZYStrokeTimer
可高度自定义,并提供了一组大量委托方法供您使用。有四个主要方法,都是自我解释的
- (void)start;
- (void)pause;
- (void)resume;
- (void)start;
BZYStrokeTimer
支持 IB_DESIGNABLE
协议,因此您可以无需构建项目即可在 Storyboard 或 nib 中操作它!
以下属性支持 IBInspectable
@property (nonatomic) IBInspectable CGFloat progress;
@property (nonatomic) IBInspectable UIColor *timerColor; //Defaults to [UIColor blackColor]
@property (nonatomic) IBInspectable CGFloat lineWidth; //Defaults to 10.0
其他选项包括
@property (nonatomic) NSString *timingFunction; //defaults to kCAMediaTimingFunctionEaseInEaseOut
@property (nonatomic) NSTimeInterval duration; //defaults at 5.0
使用 BZYStrokeTimer
有两种方式,带动画和不带动画。
设置所有所需的属性,无论是通过 Storyboard 还是如下所示程序化地
self.strokeTimer.duration = 10.0;
self.strokeTimer.timerColor = [UIColor blueColor];
self.strokeTimer.lineWidth = 5.0;
然后调用 start
。
使用 UILongPressGestureRecognizer
的示例
- (void)handleLongPress:(UILongPressGestureRecognizer *)gesture {
if(gesture.state == UIGestureRecognizerStateBegan) {
if(self.strokeTimer.isPaused) [self.strokeTimer resume];
if(!self.strokeTimer.isRunning) [self.strokeTimer start];
} else if((gesture.state == UIGestureRecognizerStateEnded || gesture.state == UIGestureRecognizerStateFailed || gesture.state == UIGestureRecognizerStateCancelled) && self.strokeTimer.isRunning) {
[self.strokeTimer pause];
}
}
如果您希望将计时器用于表示任务进度,比如网络下载,您可以手动设置 progress
属性,当任务继续时,其范围从 0.0 到 1.0。
BZYStrokeTimerDelegate
包含以下可选函数
- (void)strokeTimerWillStart:(BZYStrokeTimer *)strokeTimer;
- (void)strokeTimerDidStart:(BZYStrokeTimer *)strokeTimer;
- (void)strokeTimerWillPause:(BZYStrokeTimer *)strokeTimer;
- (void)strokeTimerDidPause:(BZYStrokeTimer *)strokeTimer;
- (void)strokeTimerWillResume:(BZYStrokeTimer *)strokeTimer;
- (void)strokeTimerDidResume:(BZYStrokeTimer *)strokeTimer;
- (void)strokeTimerWillStop:(BZYStrokeTimer *)strokeTimer;
- (void)strokeTimerDidStop:(BZYStrokeTimer *)strokeTimer;
- (BOOL)strokeTimerShouldStart:(BZYStrokeTimer *)strokeTimer;
- (BOOL)strokeTimerShouldPause:(BZYStrokeTimer *)strokeTimer;
- (BOOL)strokeTimerShouldResume:(BZYStrokeTimer *)strokeTimer;
所有 BOOL
方法默认为 YES
。
BZYStrokeTimer 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile
pod "BZYStrokeTimer"
Brendan Conron ([email protected]) 与 Rudd Fawcett ([email protected])
BZYStrokeTimer 受MIT许可证许可。有关更多信息,请参阅LICENSE文件。