IPhone application screenshot Function

Source: Internet
Author: User

IPhoneApplication ImplementationScreenshotsFunction is the content to be introduced in this article. When an iPhone user simultaneously presses the Home and lock screen keysScreenshotsBut in the application, you cannot jump out of a line to pressScreenshotsKey. The Code shared by the CocoaChina member "bobgreen" can implementScreenshotsFunction, supportedIPhone4. Retina high split screen.

 
 
  1. UIView * view = [[[[UIApplication sharedApplication] windows] objectAtIndex: 1] subviews] lastObject]; // obtain a subView of a window
  2. NSInteger index = 0; // used to name the saved png
  3. For (UIView * subView in [view subviews]) {// traverses the subViews of this view
  4. If ([subView isKindOfClass: NSClassFromString (@ "UIImageView")] | [subView isKindOfClass: NSClassFromString (@ "UIThreePartButton")])
  5. {// Find the desired subView
  6. // The key to supporting high retina scores
  7. If (uigraphicsbeginimagecontextwitexceptions! = NULL)
  8. {
  9. Uigraphicsbeginimagecontextwittions (subView. frame. size, NO, 0.0 );
  10. } Else {
  11. UIGraphicsBeginImageContext (subView. frame. size );
  12. }
  13. // Obtain the image
  14. [SubView. layer renderInContext: UIGraphicsGetCurrentContext ()];
  15. UIImage * image = UIGraphicsGetImageFromCurrentImageContext ();
  16. UIGraphicsEndImageContext ();
  17. // Save the image
  18. NSString * path = [NSHomeDirectory () stringByAppendingFormat: @ "/mongod.png", index];
  19. If ([UIImagePNGRepresentation (image) writeToFile: path atomically: YES]) {
  20. Index + = 1;
  21. NSLog (@ "Succeeded! ");
  22. }
  23. Else {
  24. NSLog (@ "Failed! ");
  25. }
  26. }
  27. }

Summary:IPhoneApplication ImplementationScreenshotsAfter the function content is introduced, there is very little content, basically code implementation. Is it a very interesting instance? I hope this article will help you.

From: http://www.cocoachina.com/iphonedev/sdk/2011/0323/2731.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.