Тест для любого
[UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeRight
[UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeLeft
(and possibly more orientations)
Затем выполните соответствующие преобразования изображения.
Это можно сделать несколькими способами, этот код не требует много кода:
/// click action saves orientation & picture:
-(void)screenshot
{
self.orientationWhenPicked = [UIDevice currentDevice].orientation;
CGImageRef screen = UIGetScreenImage();
self.image = [UIImage imageWithCGImage:screen];
CGImageRelease(screen);
}
/// somewhere else we are called for the image
-(UIImage*)getScreenshot
{
UIDeviceOrientation useOrientation = self.orientationWhenPicked;
UIImage *img = self.image;
UIGraphicsBeginImageContext(CGSizeMake(480.0f, 320.0f));
CGContextRef context = UIGraphicsGetCurrentContext();
if ( useOrientation == UIDeviceOrientationLandscapeRight )
{
CGContextRotateCTM (context, M_PI/2.0f);
[img drawAtPoint:CGPointMake(0.0f, -480.0f)];
} else {
CGContextRotateCTM (context, -M_PI/2.0f);
[img drawAtPoint:CGPointMake(-320.0f, 0.0f)];
}
UIImage *ret = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return ret;
}
Я немного изменил его перед публикацией, чтобы сделать его автономным, но он должен работать с небольшими усилиями (например, создать self.image
и т. Д.). Вы можете просто смешать их в одну функцию.