因此,我正在截取我保存到设备照片流中的子类 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, 10.0f);
UIImage *backgroundImage = [image resizableImageWithCapInsets:insets];
backgroundView.image = backgroundImage;
return backgroundView;
}
实际的打印屏幕是使用此方法完成的(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。