我需要在动画制作时捕捉视图。以下代码我用来捕捉动画时的图像。
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);
}
它只捕获结果图像
答案 0 :(得分:1)
您可以使用具有动画对象的视图副本,并使用该副本视图捕获屏幕。即。
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);