为什么不添加子图层显示在屏幕截图中?

我正在尝试追踪iPad应用程序的某些iOS代码中的错误。 在我们的观点之一中,我们已经添加了子图层以获得阴影,并确保视图的底部具有圆angular边缘。 以下是我们添加子图层的代码:

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:(UIRectCornerBottomLeft|UIRectCornerBottomRight) cornerRadii:CGSizeMake(12.0f, 12.0f)]; // Create the shadow layer shadowLayer = [CAShapeLayer layer]; [shadowLayer setFrame:self.bounds]; [shadowLayer setMasksToBounds:NO]; [shadowLayer setShadowPath:maskPath.CGPath]; shadowLayer.shadowColor = [UIColor blackColor].CGColor; shadowLayer.shadowOffset = CGSizeMake(0.0f, 0.0f); shadowLayer.shadowOpacity = 0.5f; shadowLayer.shadowRadius = 6.0f; roundedLayer = [CALayer layer]; [roundedLayer setFrame:self.bounds]; [roundedLayer setBackgroundColor:[UIColor colorFromHex:@"#e4ecef"].CGColor]; [self.layer insertSublayer:shadowLayer atIndex:0]; // Add inner view (since we're rounding corners, parent view can't mask to bounds b/c of shadow - need extra view) maskLayer = [CAShapeLayer layer]; maskLayer.frame = self.bounds; maskLayer.path = maskPath.CGPath; innerView = [[UIView alloc] initWithFrame:self.bounds]; innerView.backgroundColor = [UIColor whiteColor]; innerView.layer.mask = maskLayer; [self addSubview:innerView]; 

它在iPad的屏幕上显示出来很好,但我想以编程方式进行截图。 我用这个方法添加了一个类到UIView:

 - (UIImage*)screenshot { UIGraphicsBeginImageContext(self.frame.size); [self.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); return viewImage; } 

当我看截图的时候,它不再有我的视angular背后的圆angular或阴影。 他们为什么不露面?

在这里find一个解释: CALayer renderInContext

此外,不使用3D变换的图层,也不绘制指定backgroundFilters,filters,compositingFilter或蒙版值的图层。

它看起来像一些sublayers不能被renderInContext处理,这就是为什么他们不显示在我的屏幕截图。