Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The following code works for me. It actually doesn´t change the direction. I think you can achieve this by adding a timer which change the imagesArray. First I also tried using CAKeyframeAnimation like you but I couldn´t figure it out. So I changed to an animating image - I thought this way couldn´t be too bad, because Apple e.g. use this way also for animating the activity indicator.</p> <pre><code>-(void) myImageInitFunction { UIImage *icon = [UIImage imageNamed:@"yourIconImage"]; NSArray *imagesArray = rotatingImagesArrayOfImage(icon, 30); myImageViewThatShouldRotate.animationImages = imageArray; myImageViewThatShouldRotate.animationDuration= 2.0; [myImageViewThatShouldRotate startAnimating]; } NSArray *rotatingImagesArrayOfImage(UIImage * icon, NSInteger nFrames) { NSMutableArray *images = [NSMutableArray arrayWithObject:icon]; for (NSInteger nLoop = 1; nLoop &lt; nFrames; nLoop++) { [images addObject: [UIImage imageWithCGImage: CGImageRotatedByAngle(icon.CGImage, nLoop * ( 360 / nFrames)) ] ]; } return images; } CGImageRef CGImageRotatedByAngle(CGImageRef imgRef, CGFloat angle) { CGFloat angleInRadians = angle * (M_PI / 180); CGFloat width = CGImageGetWidth(imgRef); CGFloat height = CGImageGetHeight(imgRef); CGRect imgRect = CGRectMake(0, 0, width, height); CGAffineTransform transform = CGAffineTransformMakeRotation(angleInRadians); CGRect rotatedRect = CGRectApplyAffineTransform(imgRect, transform); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef bmContext = CGBitmapContextCreate(NULL, rotatedRect.size.width, rotatedRect.size.height, 8, 0, colorSpace, kCGImageAlphaPremultipliedFirst); CGContextSetAllowsAntialiasing(bmContext, YES); CGContextSetShouldAntialias(bmContext, YES); CGContextSetInterpolationQuality(bmContext, kCGInterpolationHigh); CGColorSpaceRelease(colorSpace); CGContextTranslateCTM(bmContext, +(rotatedRect.size.width/2), +(rotatedRect.size.height/2)); CGContextRotateCTM(bmContext, angleInRadians); CGContextTranslateCTM(bmContext, -(rotatedRect.size.width/2), -(rotatedRect.size.height/2)); CGContextDrawImage(bmContext, CGRectMake(0, 0, rotatedRect.size.width, rotatedRect.size.height), imgRef); CGImageRef rotatedImage = CGBitmapContextCreateImage(bmContext); CFRelease(bmContext); return rotatedImage; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload