0

这是我的视图层次结构:我在 Xib 中有一个视图(默认 viewControllher 的 _view),其中有一个 UIWebView 子视图。在同一个 Xib 文件中,另一个名为 floatView 的单独的第二个视图(不在 _view 内)。floatView 以编程方式添加到 UIWebView 之上,并且可以由用户拖动。在 floatView 我有一个较小的 subView (cropView)。我想使用cropView 作为裁剪框来获取它下面的可见部分webView。

这是我尝试使用的代码,但结果不是我需要的。

- (IBAction)captureImage:(id)sender {

    CGSize layerSize = self.view.bounds.size;

    UIGraphicsBeginImageContext(layerSize);

    [self.webView.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    [floatView convertRect:cropView.frame toView:self.view];

    CGRect CropFrame = cropView.frame;


    CGImageRef subImageRef = CGImageCreateWithImageInRect(image.CGImage, CropFrame);
    UIImage *subViewImage = [UIImage imageWithCGImage:subImageRef];
    UIGraphicsEndImageContext();

    UIImageWriteToSavedPhotosAlbum(subViewImage, nil, nil, nil);
}

我在相机胶卷中获得的图像是我裁剪的图像,尺寸正确,不在可见 webView 的正确位置。

我查看了其他帖子和解决方案,但找不到可以解决我的问题的帖子和解决方案。

4

1 回答 1

0

解决了(有点)。将 floatView 移到 _view 层次结构中,位于 webView 的顶部,并设法使用我在此处找到的 [view.layer presentationLayer].frame 解决方案获取其原点坐标。现在它工作...

于 2012-05-27T22:49:04.317 回答