2015-02-05 107 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]