2015-02-05 142 views
2

我有一個imageview,它每隔幾秒就會改變一次curl動畫。我想拍攝這樣的視頻,因此我正在做的是,我每秒鐘都會截取屏幕截圖並從中創建視頻。 但是,當圖像動畫時,我無法拍攝屏幕截圖,那時它將返回圖像穩定或不具有動畫效果的屏幕截圖。動畫圖像的屏幕截圖

我使用下面的代碼把圖像的截圖

{ 
    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] presentationLayer] renderInContext:context]; 

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

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

    UIGraphicsEndImageContext(); 

    return image; 
} 

沒有任何一個有關於它的主意?

在此先感謝。

-Austin

+0

儘量減少截屏之間的時期東西少 –

+0

是已經試過.. – Austin

+0

什麼區間,美試過嗎? –

回答

1

,我認爲你應該使用:

[[[[window contentView] layer] presentationLayer] renderInContext:context]; 

爲了捕捉動畫的當前狀態,而不是起點或終點狀態

0

根據你的代碼,你似乎快照了屏幕。 所以才嘗試這個辦法:

[[UIScreen mainScreen] snapshotViewAfterScreenUpdates:NO] 

否則:

[yourAnimatedView.layer.presentationLayer snapshotViewAfterScreenUpdates:NO]