David
David

Reputation: 91

Core Animation Screenshot on iPad

I'm building a scene with Core Animation which looks similar to the screensaver on the old Apple TV. A continuous stream of images (each a CALayer) passes by vertically, from the bottom to top. To achieve this, after a layer’s animation ends when it moves out of view, it is repositioned back to the bottom, assigned a new image, and reanimated. This takes place in the animationDidStop delegate method. However, I’ve noticed that if I take a screenshot when running the app on an iPad, the layers are never repositioned to the bottom, and aren’t seen again. I've isolated the problem, and I'm certain that taking screenshots is causing it. This leads me to think that taking a screenshot has an effect on animation timing. So...

  1. What impact does taking a screenshot on an iDevice have on animation?
  2. Is there a better way to achieve this effect?

Upvotes: 9

Views: 1152

Answers (2)

cowbear16
cowbear16

Reputation: 55

You could always try capturing the screenshot programmatically based upon the contents of the view, then save it as a screenshot. I do not know your objects, but this is what I have done before. All of my content for the screenshot is in CaptureView.

CGRect screenRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(CaptureView.frame.size);

CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor clearColor] set];
CGContextFillRect(ctx, screenRect);

[CaptureView.layer renderInContext:ctx];

UIImage *screenImage = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(screenImage, nil, nil, nil);
UIGraphicsEndImageContext();

Is your animation in a stationary UIImageView? If it is the image view that you want to detect going off of the screen, just use it's frame.origin.y compared to 0.

Upvotes: 1

Sunil_Vaishnav
Sunil_Vaishnav

Reputation: 425

You can use presentationLayer to capture screenshot while you animation is animating. i.e. [CaptureView.layer presentationLayer]

you can also detect touch while animating in presentationLayer of the CALayer.

Upvotes: 0

Related Questions