2012-10-25 52 views
2

On Apples技術說明網站,他們張貼代碼到屏幕捕獲。一切正常,除非它不捕獲在iOS 6下使用QLPreviewController進行預覽的文件。捕獲QLPreviewController的屏幕導致iOS 6

我想知道他們是否使用一些新的OpenGL ES來呈現文件預覽,以便它無法捕獲?從理論上講,這段代碼應該能夠捕捉屏幕上的任何東西嗎?

http://developer.apple.com/library/ios/#qa/qa1703/_index.html

- (UIImage*)screenshot 
{ 
// Create a graphics context with the target size 
// On iOS 4 and later, use UIGraphicsBeginImageContextWithOptions to take the scale into consideration 
// On iOS prior to 4, fall back to use UIGraphicsBeginImageContext 
CGSize imageSize = [[UIScreen mainScreen] bounds].size; 
if (NULL != UIGraphicsBeginImageContextWithOptions) 
    UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0); 
else 
    UIGraphicsBeginImageContext(imageSize); 

CGContextRef context = UIGraphicsGetCurrentContext(); 

// Iterate over every window from back to front 
for (UIWindow *window in [[UIApplication sharedApplication] windows]) 
{ 
    if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen]) 
    { 
     // -renderInContext: renders in the coordinate space of the layer, 
     // so we must first apply the layer's geometry to the graphics context 
     CGContextSaveGState(context); 
     // Center the context around the window's anchor point 
     CGContextTranslateCTM(context, [window center].x, [window center].y); 
     // Apply the window's transform about the anchor point 
     CGContextConcatCTM(context, [window transform]); 
     // Offset by the portion of the bounds left of and above the anchor point 
     CGContextTranslateCTM(context, 
           -[window bounds].size.width * [[window layer] anchorPoint].x, 
           -[window bounds].size.height * [[window layer] anchorPoint].y); 

     // Render the layer hierarchy to the current context 
     [[window layer] renderInContext:context]; 

     // Restore the context 
     CGContextRestoreGState(context); 
    } 
} 

// Retrieve the screenshot image 
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 

UIGraphicsEndImageContext(); 

return image; 
} 
+2

當我測試時,我可以捕獲導航欄,但不是文檔的內容。我以爲我用ios 6讀了一些關於新安全功能的地方,它可以防止捕獲預覽文檔。但我無法找到支持此文件。 – user523234

回答

0

這並不聽起來similiar但出於同樣的原因,這並不工作其實並不工作:iOS 6 UIGestures (Tap) stops working with QLPreviewController


因爲iOS 6中的QLPreviewController實際上是一個完全獨立的應用程序(單獨的過程和一切)

=>所以當你推動,你的整個應用程序移動到BG,包括窗戶。

=> QlController從來不是你的窗口的真正部分