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.
- UIView * view = [[[[UIApplication sharedApplication] windows] objectAtIndex: 1] subviews] lastObject]; // obtain a subView of a window
- NSInteger index = 0; // used to name the saved png
- For (UIView * subView in [view subviews]) {// traverses the subViews of this view
- If ([subView isKindOfClass: NSClassFromString (@ "UIImageView")] | [subView isKindOfClass: NSClassFromString (@ "UIThreePartButton")])
- {// Find the desired subView
- // The key to supporting high retina scores
- If (uigraphicsbeginimagecontextwitexceptions! = NULL)
- {
- Uigraphicsbeginimagecontextwittions (subView. frame. size, NO, 0.0 );
- } Else {
- UIGraphicsBeginImageContext (subView. frame. size );
- }
- // Obtain the image
- [SubView. layer renderInContext: UIGraphicsGetCurrentContext ()];
- UIImage * image = UIGraphicsGetImageFromCurrentImageContext ();
- UIGraphicsEndImageContext ();
- // Save the image
- NSString * path = [NSHomeDirectory () stringByAppendingFormat: @ "/mongod.png", index];
- If ([UIImagePNGRepresentation (image) writeToFile: path atomically: YES]) {
- Index + = 1;
- NSLog (@ "Succeeded! ");
- }
- Else {
- NSLog (@ "Failed! ");
- }
- }
- }
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