gpt4 book ai didi

ios - 裁剪 UIView 快照

转载 作者:行者123 更新时间:2023-11-29 11:31:17 24 4
gpt4 key购买 nike

我正在实现一个自定义的 UINavigationViewController 转换,作为动画的一部分,我想拍摄快照并转换目标 UIViewController。但是,我想对快照进行切片并独立转换部分。

在 UIView.h 中有一条注释似乎表明这是可能的,甚至是推荐的:

Creating snapshots from existing snapshots (as a method to duplicate, crop or create a resizable variant) is supported. In cases where many snapshots are needed, creating a snapshot from a common superview and making subsequent snapshots from it can be more performant.

但是,我不知道如何实际进行裁剪或从通用 super View 快照创建多个快照。

这可能吗?


注意:我确实研究过使用 UIView.drawHierarchy(in:afterScreenUpdates:) 创建一个我可以稍后裁剪的图像,但是这在 UINavigationController 转换期间失败并出现以下错误:

[Snapshotting] View (0x140853600, MTKView) drawing with afterScreenUpdates:YES inside CoreAnimation commit is not supported.

最佳答案

感谢KMT over at the Apple forums ,我找到了解决方案:

UIView.resizableSnapshotView(from:afterScreenUpdates:withCapInsets:)

传入所需的裁剪矩形和 UIEdgeInsets.zero 以正确创建裁剪快照。

关于ios - 裁剪 UIView 快照,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53289157/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com