我需要在动画制作时捕捉 View 。以下代码我用来在动画时捕获图像。
myTimer = [NSTimer scheduledTimerWithTimeInterval:0.10 target: self selectorselector(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)captureImageNSTimer*) 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);
}
它只捕获结果图像
您可以使用具有动画对象的 View 副本,并使用该副本 View 来捕获屏幕。即
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);
关于ios - 在制作动画时捕获屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20489520/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |