ios – 捕获UIView的UIImage,包括UINavigationBar

我发现这个代码非常好:
+ (UIImage *) imageWithView:(UIView *)view
{
    UIGraphicsBeginImageContextWithOptions(view.bounds.size,view.opaque,[[UIScreen mainScreen] scale]); 
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage * img = UIGraphicsGetimageFromCurrentimageContext();
    UIGraphicsEndImageContext();
    return img;
}

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

解决方法

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

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...