简体   繁体   中英

Taking screenshot only attaches white image in iOS 8 Using UIGraphicsGetImageFromCurrentImageContext

in iOS 6 & 7 this works fine, but in iOS 8 it takes a screenshot of a white screen when I attach the image.

Oddly, if I cancel, then retry, it works fine..

This is the code;

   [savingPhotoAlert dismissWithClickedButtonIndex:0   animated:YES];

    UIGraphicsBeginImageContext(self.view.bounds.size);

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

    UIImage *screenshotImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

What do you cancel? is it a kind of alertView? you have to specify when taking the screenshot(afterScreenUpdates= YES).

- (UIImage *) screenshot {
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);

    [self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES];

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM