2013-04-01 51 views
0

我想定製一個帶有UIKIT的矩形進度條,像吸引人的圖像。有沒有任何源代碼? Cocos2d與CCProgressTimer具有相同的屬性,但我無法找到任何UIKIT源代碼。 Rectangle progress bar如何自定義矩形進度條?

+0

嘿Toandk,你不應該這樣回答嗎?你說它有效;標記它回答將節省其他人看問題,並給迪彭他應得的功勞 –

回答

6

創建ShapedLayer

CAShapeLayer *layer = [CAShapeLayer layer]; 
[layer setStrokeColor:[UIColor greenColor].CGColor]; 
[layer setLineWidth:10.0f]; 

[layer setFillColor:[UIColor clearColor].CGColor]; 

要動畫

UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(10, 10, 300, 200) cornerRadius:10.0f]; 
layer.path = path.CGPath; 

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; 
animation.fromValue = [NSNumber numberWithFloat:0.0f]; 
animation.toValue = [NSNumber numberWithFloat:1.0f]; 

定義動畫持續時間

animation.duration = 4.0f; 
[layer addAnimation:animation forKey:@"myStroke"]; 

動畫添加到圖層創建radious一個矩形,在其上想要顯示

[self.view.layer addSublayer:layer]; 
+0

感謝您的代碼。有效。但是,我怎樣才能確定頂端路線的起點呢?我不擅長CAAnimation – toandk

+1

你有沒有找到解決方案來改變起點 –

+0

@SukhmeetHora在這裏一樣。你有沒有找到解決方案? – Balasubramanian