2013-04-18 27 views
0

我想動畫本地的屏幕上以這樣的方式,當屏幕上會出現在屏幕上:圖形和動畫:數字改變和彩色條

1)編號將從0動畫到即1終值 - 2 - 3 -.... 51 - 52

2)各杆將開始作爲細線,並生長側直到推崇大小。

3)所有的動畫將同時發生。 4)如果可能的話,我該如何在欄下添加陰影?

5)如何實現酒吧(圖形)?有沒有例子?

enter image description here

+1

使用定時器來增大從值0到X ,併爲其餘的show創建一個動畫[UIView beginAnimations:@「animateOn」context:NULL]; bar.frame = CGRectOffset(bar.frame,0,-50); [UIView commitAnimations]; – Nagasaki

回答

2

對於酒吧本身使用簡單的UIView實例。 導入後<QuartzCore/QuartzCore.h>您可以通過圖層爲它們添加邊框和陰影(view.layer)。 見的CALayer:https://developer.apple.com/library/ios/#documentation/graphicsimaging/reference/CALayer_class/Introduction/Introduction.html

borderWidth, borderColor, backgroundColor 
shadowOpacity, shadowRadius, shadowOffset, shadowColor, shadowPath 

對於數字的動畫,使用計時器,增加數量,直到達到實際值。水木清華。像這樣:

CGFloat animationDuration = 1.0; 
self.targetValue = 50; 
[NSTimer scheduledTimerWithTimeInterval:animationDuration/targetValue target:self selector:@selector(increaseValue:) userInfo:nil repeats:YES]; 

,然後像這樣的方法:

- (void)increaseValue:(NSTimer*)timer; 
{ 
    self.label.text = [NSString stringWithFormat: @"%d", [self.label.text intValue]+1]; 

    if ([self.label.text intValue] == self.targetValue) { 
     [timer invalidate]; 
    } 
} 

對於動畫,只是調整的幀:

[UIView animateWithDuration:animationDuration animations:^{ 
    CGRect rect = self.barView.frame; 
    rect.size.width = self.targetValue; 
    self.barView.frame = rect; 
}]; 
+0

謝謝,我如何確保一切都同時發生? –

+0

只爲所有動畫使用相同的動畫持續時間。它會一次運行。 – calimarkus