转换并截取视图的截图?

时间:2014-12-07 11:16:58

标签: ios cgaffinetransform

我有一个位于特定变换的视图。我想截取该视图的截图,但在渲染之后它没有采用变换的值。

我的观点

dragView = [[DragbleView alloc] initWithFrame:CGRectMake(10, 200, 200, 90)];
dragView.contentView = textField;
dragView.transform = CGAffineTransformMakeRotation (-0.663247);
[self.view addSubview:dragView];

我的截图代码

UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, [UIScreen mainScreen].scale);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;

问题 After taking screenshot it always comes horizontal neglecting the value of transform

1 个答案:

答案 0 :(得分:0)

您可以拍摄要保留在快照图像中的所有子视图的父视图的快照,父视图为self.view。然后保留dragView的变换。

UIImage *mainImage = [self imageWithView:self.view];

您忘记了UIGraphicsEndImageContext()函数中的btnSaveClicked