UIPickerView gets darker in the screenshot

I had to change the navigation under certain circumstances, and due to the complexity of the transitions, I took the paint and screenshot until the transition was complete. In almost cases, this works very well, but there is a moment that bothers me. I have a view controller with two select views:

enter image description here

But the screenshot does not work well on this VC. I get the following:

enter image description here

In both cases, a code is used that takes a screenshot:

- (UIImage *)takeScreenshot {
    CALayer *layer = [[UIApplication sharedApplication] keyWindow].layer;
    UIGraphicsBeginImageContext(layer.frame.size);
    [layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
    return screenshot;
}

Does anyone know how this could happen?

+4
source share
2 answers

You can try using a different method for the screenshot. Apple introduced in iOS 7 some ways to quickly view snapshots.

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0);
[self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES];
UIImage *im = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

- Apple, , 2 . pb, , . , .

+4
UIGraphicsBeginImageContext(self.window.bounds.size);

[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

NSData * data = UIImagePNGRepresentation(image);

[data writeToFile:@"image.png" atomically:YES];

, : -

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(self.window.bounds.size, NO,[UIScreen mainScreen].scale);

else

UIGraphicsBeginImageContext(self.window.bounds.size);
+1

All Articles