Tom Johnson
Tom Johnson

Reputation: 73

How to make an image from iPhones library rotate in iOS?

I have an application which displays the artwork from a chosen song selected from the iPod library and would like to make it spin constantly.

The code so far is as follows:

-(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];
}

Upvotes: 2

Views: 248

Answers (1)

C0L.PAN1C
C0L.PAN1C

Reputation: 12243

Use Quartz Core Framework. This is untested but I imagine it should work in theory.

#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"];

Upvotes: 3

Related Questions