簡體   English   中英

動畫時捕獲屏幕

[英]Capture Screen while animating

我需要在制作動畫時捕獲視圖。 我正在使用以下代碼在動畫時捕獲圖像。

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

它僅捕獲結果圖像

您可以使用具有動畫對象的視圖副本,並使用該副本視圖捕獲屏幕。

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