2012-07-14 43 views
0

我在iOS中創建旋鈕按鈕。圖形設計師爲我提供了png圖層,因此我使用圖像上下文來混合圖層。CGGraphics圖像上下文動畫旋轉在iOS 5.1中

旋轉時,只有一部分圖層旋轉。我的目標是動畫這些旋轉。

目前,我使用

- (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event 
- (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event 
- (BOOL)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event 
這些方法我計算圖像所需的旋轉和繪製

這工作正常。我的障礙是,在

- (BOOL)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event 

我想做一個「捕捉」動畫。我怎樣才能做到這一點? 我不確定在這種情況下如何使用仿射變換由於混合。下面的方法是我如何建立圖像:

- (UIImage *)knobImageWithRadians:(float)radians 
{ 
UIImage *i05 = [UIImage imageNamed:@"05 - Metal Over Empty Space - ROTATE ME.png"]; 
UIImage *i04 = [UIImage imageNamed:@"04 - Inner Knob.png"]; 
UIImage *i03 = [UIImage imageNamed:@"03 - Over Knob Metal - (OVERLAY BLEND) - ROTATE ME.png"]; 
UIImage *i02 = [UIImage imageNamed:@"02 - Numbers and Dashes - ROTATE ME.png"]; 
UIImage *i01 = [UIImage imageNamed:@"01 - Reflective Overlay - (COLOR DODGE BLEND).png"]; 

CGSize size = i11.size;  

UIGraphicsBeginImageContext(size); 
CGContextRef bitmap = UIGraphicsGetCurrentContext(); 
CGContextTranslateCTM(bitmap, size.width/2, size.height/2); 


[i04 drawInRect:CGRectMake(-i04.size.width/2, -i04.size.height/2, i04.size.width, i04.size.height) blendMode:kCGBlendModeNormal alpha:1.0]; 

CGContextRotateCTM(bitmap, radians); 
[i03 drawInRect:CGRectMake(-i03.size.width/2, -i03.size.height/2, i03.size.width, i03.size.height) blendMode:kCGBlendModeOverlay alpha:1.0]; 

[i02 drawInRect:CGRectMake(-i02.size.width/2, -i02.size.height/2, i02.size.width, i02.size.height) blendMode:kCGBlendModeNormal alpha:1.0]; 
CGContextRotateCTM(bitmap, -radians); 

[i01 drawInRect:CGRectMake(-i01.size.width/2, -i01.size.height/2, i01.size.width, i01.size.height) blendMode:kCGBlendModeColorDodge alpha:1.0]; 

UIImage* blendedImage = UIGraphicsGetImageFromCurrentImageContext(); 

UIGraphicsEndImageContext(); 

return blendedImage; 
} 

UPDATE:

現在,我只是讓它直接扣沒有任何動畫。

回答

2

您必須通過定期以新角度重新繪製圖像來自己動畫。或者想出只使用源代碼而不是合成的視覺效果,這樣你可以將每個圖像放在一個單獨的圖層中。