そのため、デバイスのフォト ストリームに保存するサブクラス化された 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 です。