Capturing full screenshot with status bar in iOS programmatically

后端 未结 7 2376
执笔经年
执笔经年 2020-12-14 03:45

I am using this code to capture a screenshot and to save it to the photo album.

-(void)TakeScreenshotAndSaveToPhotoAlbum
{
   UIWindow *window = [UIApplicati         


        
7条回答
  •  醉梦人生
    2020-12-14 04:33

    The status bar is actually in its own UIWindow, in your code you are only rendering the view of your viewcontroller which does not include this.

    The "official" screenshot method was here but now seems to have been removed by Apple, probably due to it being obsolete.

    Under iOS 7 there is now a new method on UIScreen for getting a view holding the contents of the entire screen:

    - (UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates
    

    This will give you a view which you can then manipulate on screen for various visual effects.

    If you want to draw the view hierarchy into a context, you need to iterate through the windows of the application ([[UIApplication sharedApplication] windows]) and call this method on each one:

    - (BOOL)drawViewHierarchyInRect:(CGRect)rect afterScreenUpdates:(BOOL)afterUpdates
    

    You may be able to combine the two above approaches and take the snapshot view, then use the above method on the snapshot to draw it.

提交回复
热议问题