2013-02-01 44 views
2

我有一個應用程序,它顯示從iPod庫中選擇的歌曲中的藝術作品,並希望不斷旋轉。如何在iPhone中旋轉iOS中的圖像?

到目前爲止的代碼如下:

-(void)chosen:(MPMediaItem*)song withObject:(id)obj 
{ 

    AppDelegate* app = (AppDelegate*)[[UIApplication sharedApplication] delegate]; 

    //ARTWORK STUFF 
    UIImage *artworkImage = [UIImage imageNamed:@"noArtworkImage.png"] 

    MPMediaItemArtwork *artwork = [song valueForProperty: MPMediaItemPropertyArtwork]; 

    if (artwork) 
    { 
     artworkImage = [artwork imageWithSize: CGSizeMake (200, 200) ]; 
    } 
    [app.viewController.artworkImage1 setImage:artworkImage]; 
} 

回答

3

使用Quartz核心框架。這是未經測試的,但我想它應該在理論上起作用。

#import <QuartzCore/QuartzCore.h> 

CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; 
fullRotation.fromValue = [NSNumber numberWithFloat:0]; 
fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)]; 
fullRotation.duration = 6; 
fullRotation.repeatCount = 1e100f; 
[app.viewController.artworkImage1.layer addAnimation:fullRotation forKey:@"360"]; 
+0

這工作完美無瑕,非常感謝。 –