ios – 在屏幕截图期间,拉伸的UIView背景被截断

所以,我正在截取一个子类UIView的截图,我将其保存到设备的照片流中.

问题:

问题是我使用resizableImageWithCapInsets向我的UIView添加拉伸背景,但是这个背景在右侧被截断,我不明白为什么.如果有人可以帮助我,我将非常感激.

我通过以下方式将拉伸的背景添加到我的UIView:

[diagramBase addSubview:[self addTileBackgroundOfSize:diagramBase.frame 
andType:@"ipad_diagram_border.png"]];

哪个调用方法

- (UIImageView *) addTileBackgroundOfSize:(CGRect)frame 
andType:(Nsstring *)type
{
frame.origin.x = 0.0f;
frame.origin.y = 0.0f;

UIImageView *backgroundView = [[UIImageView alloc] initWithFrame:frame];
UIImage *image = [UIImage imageNamed:type];
UIEdgeInsets insets = UIEdgeInsetsMake(10.0f,10.0f,10.0f);
UIImage *backgroundImage = [image resizableImageWithCapInsets:insets];
backgroundView.image = backgroundImage;

return backgroundView;
}

实际的printcreen是用这个方法完成的(RINDiagramView是我的子类UIView的名字,我正在截取它的截图).旋转是在那里,因为我需要在保存时旋转图像,但我注释掉那部分,这不是背景的行为怪异.

- (UIImage *) createSnapshotOfView:(RINDiagram *) view
{
CGRect rect = [view bounds];
rect.size.height = rect.size.height - 81.0f;
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *capturedScreen = UIGraphicsGetimageFromCurrentimageContext();
UIGraphicsEndImageContext();
UIImage *finalImage = [[UIImage alloc] initWithCGImage: capturedScreen.CGImage
                                            scale: 1.0
                                      orientation: UIImageOrientationLeft];
return finalImage;
}

我使用Xcode 5.1,一切都是以编程方式完成的(没有故事板等).基础SDK是iOS 7.1.

解决方法

如果您正在使用iOS 7,您可以使用新的 drawViewHierarchyInRect:afterScreenUpdates:以及Apple认为真正具有高效性的相关方法.

即使您的目标是iOS 6,也应该尝试一下,看看是否会遇到同样的问题.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...