Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Screenshot of Mobile phone by IOS

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to achieve IOS mobile phone screenshot, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Main steps of screenshot of IOS mobile phone

1. Create a drawing context

two。 Draw the screen into it

3. Save the picture to the album

4. Turn off the drawing context

The realization of screenshot of IOS mobile phone

-(IBAction) truncation: (UIButton *) sender {

/ / take a screenshot after a delay of 2 seconds

Dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t) (2.0 * NSEC_PER_SEC)), dispatch_get_main_queue (), ^ {

# pragma mark create Screenshot

/ / 1. Create a graphic context, which is equivalent to a canvas

UIGraphicsBeginImageContext (self.view.frame.size)

/ / 2. Draw the screen into it

[self.view.layerrenderInContext:UIGraphicsGetCurrentContext ()]

UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext ()

/ / 3. Save the picture to the album

UIImageWriteToSavedPhotosAlbum (newImage, self,@selector (p_w_picpath:didFinishSavingWithError:contextInfo:), nil)

/ / 4. Turn off the drawing context

UIGraphicsEndImageContext ()

});

}

# pragma mark determines whether the screenshot is created successfully-it can be implemented using a third-party library

-(void) p_w_picpath: (UIImage *) p_w_picpath didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo {

If (error) {

/ / NSLog (@ "Save failed")

[MBProgressHUD showError:@ "failed to save, please check whether the application has permission to access the album"]

} else {

/ / NSLog (@ "saved successfully")

[MBProgressHUD showSuccess:@ "saved successfully"]

}

}

The above is all the contents of the article "how to take screenshots on IOS". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report