0
我目前有一個計時器,在該計時器下面有一個循環線 - 倒計時線。這根據我傳遞給_percent的秒數進行動畫處理。使用UIBezierPath自定義定時器動畫
我想要另一個圓形的輪子,描繪秒。然而,我正在努力如何在_percent中留下每秒一秒的動畫。例如如果百分比是100,我想圈出100倍持續1秒的動畫循環。 (以及實現如下所示的動畫效果)
這是爲了清晰起見而繪製的圖:) 3的第一行顯示了它當前的樣子,最下面的3行顯示了我想要的效果......
這裏是我激發關閉計時器在我的視圖控制器類:
-(void)viewDidLoad
{
CPCircleCountdownView *m_testView;
m_testView.percent = 100;
}
- (IBAction)StartTimerButtonPressed:(id)sender
{
// Kick off a timer to count it down
m_timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(decrementSpin) userInfo:nil repeats:YES];
}
- (void)decrementSpin
{
// If we can decrement our percentage, do so, and redraw the view
if (m_testView.percent > 0) {
m_testView.percent = m_testView.percent - 1;
[m_testView setNeedsDisplay];
}
else {
[m_timer invalidate];
m_timer = nil;
}
}
,這裏是我的CPCountdownView這裏我想補充新的圓形動畫持續每秒左一秒鐘。理論上的兩個動畫應該同時完成。
#import "CPCircleCountdownView.h"
@interface CPCircleCountdownView()
{
CGFloat startAngle;
CGFloat endAngle;
}
@end
@implementation CPCircleCountdownView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.backgroundColor = [UIColor clearColor];
//get start and end angles
startAngle = M_PI * 1.5;
endAngle = startAngle + (M_PI * 2);
}
return self;
}
- (void)drawRect:(CGRect)rect
{
//Display arc percent
//NSString *textContent = [NSString stringWithFormat:@"%d", self.percent]; //TODO: Pass total number of seconds int
//-------------------------
UIBezierPath* bezierPath = [UIBezierPath bezierPath];
// Create our arc, with the correct angles
[bezierPath addArcWithCenter:CGPointMake(rect.size.width/2, rect.size.height/2)
radius:130
startAngle:startAngle
endAngle:(endAngle - startAngle) * (_percent/_overallScore) + startAngle
clockwise:YES];
// Set the display for the path, and stroke it
bezierPath.lineWidth = 2;
[[UIColor colorWithRed:122.0/255.0 green:197.0/255.0 blue:205.0/255.0 alpha:1.0] setStroke];
[bezierPath stroke];
//-------------------------
}
任何幫助將是巨大的我是比較新的,所以如果你可以給我的例子,這將是巨大的:)謝謝
問題是,cabasicanimation在應用程序關閉並再次打開時被刪除。意味着沒有更多的動畫。 – Ryan
足夠簡單,可以添加通知並重新創建最後一次關閉的動畫。 – MDB983