ПРОБЛЕМА
Я использую UIGraphicsBeginImageContextWithOptions, чтобы сохранить скриншот в UIImage. Хотя это работает, в результирующем UIImage отсутствуют тени и градиенты.
Как мне заставить его также делать скриншоты слоя?
ПРОВЕРОЧНЫЙ КОД, ПОКАЗЫВАЮЩИЙ ПРОБЛЕМУ
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
@implementation ViewController
- (void)viewDidLoad {
//super
[super viewDidLoad];
//background
self.view.backgroundColor = [UIColor whiteColor];
//container
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 300, 200)];
container.backgroundColor = [UIColor blackColor];
[self.view addSubview:container];
//circle
UIView *circle = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 10, 10)];
circle.backgroundColor = [UIColor whiteColor];
circle.layer.cornerRadius = 5;
circle.layer.shadowColor = [UIColor redColor].CGColor;
circle.layer.shadowOffset = CGSizeZero;
circle.layer.shadowOpacity = 1;
circle.layer.shadowRadius = 10;
circle.layer.shadowPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(-10, -10, 30, 30)].CGPath;
[container addSubview:circle];
//screenshot
UIGraphicsBeginImageContextWithOptions(container.bounds.size, container.opaque, 0.0);
[container.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//image view
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(10, 568-200-20-10, 300, 200)];
iv.image = screenshot;
[self.view addSubview:iv];
}
@end
СКРИНШОТ СИМУЛЯТОРА, ПОКАЗЫВАЮЩИЙ ПРОБЛЕМУ
Верхняя область — исходный вид. Нижняя область — это UIImageView со скриншотом.