Pour l'animation ur tourner ImageView en le transformant:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationRepeatAutoreverses:NO];
[UIView setAnimationRepeatCount:0];
imageViewObject.transform = CGAffineTransformMakeRotation(angle);
[UIView commitAnimations];
et lorsque vous enregistrez l'image en données de base, puis avant l'image d'économie faites pivoter cette image à l'angle imageViewRotated de la position actuelle. pour une rotation UIImage, utilisez ceci: // rappelez-vous que l'angle doit être en radian, s'il n'est pas en radian, puis convertissez l'angle en radian.
- (UIImage*) rotateInRadians:(float)radians
{
const size_t width = self.size.width;
const size_t height = self.size.height;
CGRect imgRect = (CGRect){.origin.x = 0.0f, .origin.y = 0.0f, .size.width = width, .size.height = height};
CGRect rotatedRect = CGRectApplyAffineTransform(imgRect, CGAffineTransformMakeRotation(radians));
/// Create an ARGB bitmap context
CGContextRef bmContext = CreateARGBBitmapContext(rotatedRect.size.width, rotatedRect.size.height, 0);
if (!bmContext)
return nil;
CGContextSetShouldAntialias(bmContext, true);
CGContextSetAllowsAntialiasing(bmContext, true);
CGContextSetInterpolationQuality(bmContext, kCGInterpolationHigh);
/// Rotation happen here (around the center)
CGContextTranslateCTM(bmContext, +(rotatedRect.size.width * 0.5f), +(rotatedRect.size.height * 0.5f));
CGContextRotateCTM(bmContext, radians);
/// Draw the image in the bitmap context
CGContextDrawImage(bmContext, (CGRect){.origin.x = -(width * 0.5f), .origin.y = -(height * 0.5f), .size.width = width, .size.height = height}, self.CGImage);
/// Create an image object from the context
CGImageRef rotatedImageRef = CGBitmapContextCreateImage(bmContext);
UIImage* rotated = [UIImage imageWithCGImage:rotatedImageRef];
/// Cleanup
CGImageRelease(rotatedImageRef);
CGContextRelease(bmContext);
return rotated;
}
J'espère que cela vous aide.
Je stocke effectivement les images au format JPEG et je pense que cela prend en charge l'orientation. Mais puis-je accéder à cela à partir de Cocoa? – Kamchatka