One, the entire project document.
Two, the code
Viewcontroller.m
#import "ViewController.h" #import <QuartzCore/QuartzCore.h> @interface Viewcontroller () @end @implementation viewcontroller-(void) viewdidload {[Super viewdidload]; Do any additional setup after loading the view, typically from a nib.} #pragma-mark-doclickactions-(void) Touchesbegan: (Nsset *) touches withevent: (uievent *) event{[self screenshot];} #pragma-mark-functions//screenshot function-(void) screenshot{uigraphicsbeginimagecontext (self.view.bounds.size); [Self.view.layer Renderincontext:uigraphicsgetcurrentcontext ()]; UIImage *image= Uigraphicsgetimagefromcurrentimagecontext (); Uigraphicsendimagecontext (); NSLog (@ "image:%@", image); Uiimageview *imaview = [[Uiimageview alloc] initwithimage:image]; Imaview.frame = CGRectMake (0, 700, 500, 500); [Self.view Addsubview:imaview]; Uiimagewritetosavedphotosalbum (image, self, nil, nil); }
Ios-screenshot function implementation.