試驗要麼
[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
等)。你可以將它們混合成一個函數。
請注意,UIGetScreenImage()已被Apple重新制作,如果使用此功能,您的應用程序將被拒絕:http://www.drahtwerk.biz/CN/Blog.aspx/iOS-4-updates-延遲/?newsID = 45 – 2010-07-27 12:32:13