I have a UIView
which contains another UIView
with an UIImage
.
dView=[[drawView alloc]initWithFrame:myUIView.frame];
[dView newMaskWithColor:[UIColor colorWithPatternImage:chosenImage]];
[myUIView addSubview:dView];
And by using this code, I erased a part of it, and it looks like this now:
and now I added a layer
behind this view, and presented another image
in that layer
.
[myUIView.layer insertSublayer:_videoPreviewLayer below:dView.layer];
and now it looks like this: (this is the screenshot manually taken on device)
When I try to screenshot the above view programmatically, the result is:
I dont why the newly added videopreview layer doesnt appeared in the screenshot.Here is my screenshot method.
-(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);
}
I am calling this method on a button click in my view controller.
I even tried capturing the window that is suggested from this answer, still I dont get the result I get from screenhotting manually.
Is there any way to capture the top most view that is shown to user ?