简体   繁体   English

动画时捕获屏幕

[英]Capture Screen while animating

I need to capture view while it is animating. 我需要在制作动画时捕获视图。 Following code i am using to capture image while animation. 我正在使用以下代码在动画时捕获图像。

myTimer = [NSTimer scheduledTimerWithTimeInterval:0.10 target: self selector:@selector(captureImage:) userInfo: nil repeats: YES];

[[NSRunLoop mainRunLoop] addTimer:myTimer forMode:NSRunLoopCommonModes];

UIImage * toImage = [[AppDelegateObj resultedImageArray]objectAtIndex:1];

[UIView transitionWithView:beforeImgView 
duration:5 
options:UIViewAnimationOptionTransitionCrossDissolve 
animations:^{ 
beforeImgView.image = toImage;
} 
completion:^(BOOL finished) {
[myTimer invalidate];
}];
}

-(void)captureImage:(NSTimer*) t {
    CALayer *layer;
    layer = [self.view.layer presentationLayer];
    UIGraphicsBeginImageContext(self.view.bounds.size);
    CGContextClipToRect (UIGraphicsGetCurrentContext(),self.view.frame);
    [layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}

It only captures resultant image 它仅捕获结果图像

You can use the copy of the view which has animating objects and use that copy view for capturing the screen. 您可以使用具有动画对象的视图副本,并使用该副本视图捕获屏幕。 ie

UIView *copyView = [self.view mutableCopy];

CALayer *layer;
layer = [copyView.layer presentationLayer];
UIGraphicsBeginImageContext(self.view.bounds.size);
CGContextClipToRect (UIGraphicsGetCurrentContext(),copyView.frame);
[layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM