2012-01-12 77 views
-1

Xcode4.2 SDK是5.0截圖在iOS5中可以正常工作,但在iOS4中不能正常工作

已添加QuartzCore.framework。

#import <QuartzCore/QuartzCore.h> 
@property (retain, nonatomic) IBOutlet UIImageView *imageView; 

-(UIImage*)getShot 
{ 
    CGSize imageSize = CGSizeMake(320, 460); 
    UIGraphicsBeginImageContext(imageSize); 
    [imageView.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return viewImage; 
} 

它在iOS5中正常工作,但在iOS4中不起作用。

無論我用

UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0) 

UIGraphicsBeginImageContext(imageSize) 

它並不能幫助。

+0

我只知道它的Xcode4.2的問題。如果我使用Xcode4.1,它只支持iOS4,它在iOS4中工作正常。 – Patrick 2012-01-12 05:44:57

回答

0
- (UIImage*) takeScreenshot 
{ 
     if (iosVersionIsAtLeast(4.0)) 
       UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, 0.0); 
     else 
       UIGraphicsBeginImageContext(self.frame.size); 
     [self.layer renderInContext:UIGraphicsGetCurrentContext()]; 

     // save to UIImage 
     UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); 
     UIGraphicsEndImageContext(); 
     return screenshot; 
} 
+0

如果我想使用iosVersionIsAtLeast()方法,我需要導入什麼? – Patrick 2012-01-12 04:56:10

+0

無論我使用UIGraphicsBeginImageContextWithOptions()還是UIGraphicsBeginImageContext(),都沒有幫助。 – Patrick 2012-01-12 05:16:29

相關問題