Ios 在设置动画时捕捉屏幕

Ios 在设置动画时捕捉屏幕,ios,animation,calayer,screen-capture,Ios,Animation,Calayer,Screen Capture,我需要捕捉视图,而它是动画。下面的代码是我用来捕捉动画时的图像 myTimer = [NSTimer scheduledTimerWithTimeInterval:0.10 target: self selector:@selector(captureImage:) userInfo: nil repeats: YES]; [[NSRunLoop mainRunLoop] addTimer:myTimer forMode:NSRunLoopCommonModes]; UIImage * to

我需要捕捉视图,而它是动画。下面的代码是我用来捕捉动画时的图像

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);
}

它仅捕获结果图像

您可以使用具有动画对象的视图副本,并使用该副本视图捕获屏幕。i、 e

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);

它因错误而崩溃---[UIView mutableCopyWithZone:]:在将代码的第一行替换为NSData*tempArchiveView=[NSKeyedArchivedDataWithRootObject:self.view]后,将无法识别的选择器发送到Instance;UIView*copyView=[NSKeyedUnarchiver unarchiveObjectWithData:tempArchiveView];空白屏幕保存在照片库中UIView未实现复制方法。问题的解决方案是什么?嘿,您可以使用这行代码处理UIView对象UIView*copyView=[NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver ArchiveDataWithRootObject:self.view];