屏幕截图顶部最高层/视图
问题描述:
我有一个UIView
其中包含另一个UIView
与UIImage
。屏幕截图顶部最高层/视图
dView=[[drawView alloc]initWithFrame:myUIView.frame];
[dView newMaskWithColor:[UIColor colorWithPatternImage:chosenImage]];
[myUIView addSubview:dView];
,并通过使用this代码,我抹去它的一部分,现在看起来是这样的:
,现在我加入了layer
这种观点的背后,在layer
提出的另一个image
。
[myUIView.layer insertSublayer:_videoPreviewLayer below:dView.layer];
,现在,它看起来像这样:(这是手动采取装置的屏幕截图)
我不为什么新增加的videopreview图层不出现在屏幕截图中。这里是我的屏幕截图方法。
-(void)takeSnapShot{
UIView *topView = [[[[UIApplication sharedApplication] keyWindow] subviews] lastObject]; //tried this too
//capture the screenshot of the uiimageview and save it in camera roll
UIGraphicsBeginImageContext(self.myUIView.frame.size);
[self.myUIView.layer renderInContext:UIGraphicsGetCurrentContext()]; // tried this
[self.dView.layer renderInContext:UIGraphicsGetCurrentContext()]; //tried this
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; //tried this
[topView.layer renderInContext:UIGraphicsGetCurrentContext()]; //tried this
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
}
我在按钮上点击我的视图控制器调用此方法。
我甚至试图捕获从这answer建议的窗口,仍然我没有得到我手动从屏幕截图得到的结果。
有没有什么方法可以捕获显示给用户的最顶层视图?
答
退房这个帖子:Why don't added sublayers show up in screenshot?
似乎子层不是由renderInContext方法处理。
当你想捕捉截图时,尝试从UIImageView中的预览图层中存储一帧,然后你应该能够手动将该帧放在你的蒙版下方并截图超级视图。