cuốn sách gpt4 ai đã làm

swift - 屏幕截图 - 奇怪的灰色区域

In lại Tác giả: Walker 123 更新时间:2023-11-28 08:12:27 27 4
mua khóa gpt4 Nike

我正在 try catch 我当前所在的屏幕,因此当我覆盖下一个 View Controller 时,我可以使它成为它后面的 ImageView 并使其显示为半透明。这是有效的,但现在它在中间产生了一些奇怪的灰色。这是我正在使用的代码:

    func requestOverride(overrideReason : String, notificationName : Notification.Name) {

captureScreen { (image) in
ManagerOverride.image = image

let vc = UIStoryboard(name: "ManagerOverride", bundle: nil).instantiateViewController(withIdentifier: "overrideNav") as! UINavigationController
let over = vc.viewControllers.first as! ManagerOverrideViewController
let _ = over.view
over.overrideReason.text = overrideReason
over.notifyName = notificationName
UIApplication.shared.keyWindow?.currentViewController()?.present(vc, animated: true, completion: nil)
}
}

func captureScreen(completion: @escaping (UIImage) -> ()) {
let view = UIApplication.shared.keyWindow!.currentViewController()!.view!
UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, UIScreen.main.scale)
view.layer.render(in: UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
completion(image!)
}

这是我得到的结果:

我不知道为什么要这样做

câu trả lời hay nhất

不幸的是,在上下文中渲染 View 并不是 100% 的方法。并非所有 View 和图层属性都保存在屏幕截图中。我知道的一个是 layer.mask(或者可能是 masksToBounds 标志的状态)。这可能是您的问题,某些 View 使用了 mask ,在屏幕上它被 mask 了,但在屏幕截图上呈现的就像 mask 不存在一样。

关于swift - 屏幕截图 - 奇怪的灰色区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43374227/

27 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress