捕获UIView的UIImage,包括UINavigationBar

csc*_*uff 8 animation uinavigationbar uiview uiimage ios

我发现这个代码非常好:

+ (UIImage *) imageWithView:(UIView *)view
{
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, [[UIScreen mainScreen] scale]); 
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}
Run Code Online (Sandbox Code Playgroud)

但我也需要捕获UINavigationBar,因为我想在我的UIStoryboardSegue中将图像用作过渡层.有任何想法吗?

Fab*_*ser 7

使用视图的窗口作为视图,因此也将包含导航栏和状态栏.如果您需要删除状态栏,则必须裁剪图像.