#import "ViewController.h"
@interface Viewcontroller ()
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Additional setup after loading the view, typically from a nib.
}
-(void) touchesended: (Nsset *) touches withevent: (Uievent *) event
{
NSLog (@ "Start screenshot");
[Self cutterviewtodocument];
}
-(void) cutterviewtodocument
{
UIWindow *screenwindow = [[UIApplication sharedapplication] Keywindow];
Uigraphicsbeginimagecontext (screenWindow.frame.size);
[Screenwindow.layer Renderincontext:uigraphicsgetcurrentcontext ()];
UIImage *screenshot = Uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();
NSData *screenshotpng = uiimagepngrepresentation (screenshot);
Nserror *error = nil;
BOOL issuccess= [Screenshotpng writetofile:[[nshomedirectory () stringbyappendingpathcomponent:@ "Documents"] stringbyappendingpathcomponent:@ "Screen.png"] options:nsatomicwrite error:&error];
NSLog (@ "%@", Nshomedirectory ());
if (issuccess) {
NSLog (@ "screenshot success");
}else{
NSLog (@ "screenshot failed");
}
}
-(void) didreceivememorywarning {
[Super didreceivememorywarning];
Dispose of any resources the can be recreated.
}
@end
Implementation of the screenshot function of IOS