-(UIImage*)_imageForViewOrLayer:(id)viewOrLayer{if([viewOrLayerisKindOfClass:[UIViewclass]]){if(_usesDrawViewHierarchyInRect){return[UIImagefb_imageForView:viewOrLayer];}else{return[UIImagefb_imageForViewLayer:viewOrLayer];}}elseif([viewOrLayerisKindOfClass:[CALayerclass]]){return[UIImagefb_imageForLayer:viewOrLayer];}else{[NSExceptionraise:@"Only UIView and CALayer classes can be snapshotted"format:@"%@",viewOrLayer];}returnnil;}
+(UIImage*)fb_imageForView:(UIView*)view{CGRectbounds=view.bounds;NSAssert1(CGRectGetWidth(bounds),@"Zero width for view %@",view);NSAssert1(CGRectGetHeight(bounds),@"Zero height for view %@",view);// If the input view is already a UIWindow, then just use that. Otherwise wrap in a window.UIWindow*window=[viewisKindOfClass:[UIWindowclass]]?(UIWindow*)view:view.window;BOOLremoveFromSuperview=NO;if(!window){window=[[UIApplicationsharedApplication]fb_strictKeyWindow];}if(!view.window&&view!=window){[windowaddSubview:view];removeFromSuperview=YES;}UIGraphicsBeginImageContextWithOptions(bounds.size,NO,0);[viewlayoutIfNeeded];[viewdrawViewHierarchyInRect:view.boundsafterScreenUpdates:YES];UIImage*snapshot=UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();if(removeFromSuperview){[viewremoveFromSuperview];}returnsnapshot;}