我有一个图像视图,它每隔几秒钟就会随着卷曲动画而改变。我想拍一段视频,所以我所做的就是,我每秒都会截取屏幕截图,并从中创建视频。但是当图像是动画的时候,我无法截取屏幕截图,那时它会返回图像稳定或没有动画的截图。
我使用下面的代码来截取图像的屏幕截图
{
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
发布于 2015-03-01 03:22:55
我认为你应该使用:
[[[[window contentView] layer] presentationLayer] renderInContext:context];为了捕获动画的当前状态,而不是源或目标状态
发布于 2017-03-02 16:02:04
根据您的代码,您似乎是在截取屏幕。所以你可以试试这个:
[[UIScreen mainScreen] snapshotViewAfterScreenUpdates:NO]否则:
[yourAnimatedView.layer.presentationLayer snapshotViewAfterScreenUpdates:NO]https://stackoverflow.com/questions/28337101
复制相似问题