gpt4 book ai didi

swift - CGAffineTransform - 使用后像素化

转载 作者:行者123 更新时间:2023-11-30 10:39:27 27 4
gpt4 key购买 nike

问题:

当使用 CGAffineTransform 时,我失去了 UIView 及其所有 subview 的质量。

代码

我当前正在运行以下代码来缩放和移动我的 UIView。

    func animate(show: Bool, navigationController: UINavigationController) {
let viewWidth = UIScreen.main.bounds.width
let scale: CGFloat = 0.7

UIView.animate(withDuration: 0.5, animations: {

if !show {
var t = CGAffineTransform.identity
t = t.scaledBy(x: scale,
y: scale)
t = t.translatedBy(x: viewWidth * 0.6, y: 0)
navigationController.view.transform = t
} else {
navigationController.view.transform = .identity
}

}) { (complete) in
if show {
let sideMenuView = UIApplication.shared.keyWindow?.viewWithTag(-253)
sideMenuView?.removeFromSuperview()
}
}
}

但是当我返回到原始状态时,一切都是像素化且质量低下。

我已经在手机和模拟器上尝试过。我已经删除了比例因子,但问题仍然存在。我也尝试过将值设置为原始值。

示例

     var t = CGAffineTransform.identity
t = t.scaledBy(x: 1,
y: 1)
t = t.translatedBy(x: 0, y: 0)
navigationController.view.transform = t

问题

使用 CGAffineTransform 时有办法保持质量吗?

谢谢大家

托马斯

最佳答案

已解决

这真的很简单。

设置 rasterizationScale 解决了该问题。

    func animate(show: Bool, navigationController: UINavigationController) {
let viewWidth = UIScreen.main.bounds.width
let scale: CGFloat = 0.7
navigationController.view.layer.rasterizationScale = UIScreen.main.scale

UIView.animate(withDuration: 0.5, animations: {

if !show {
var trans = CGAffineTransform.identity
trans = trans.scaledBy(x: scale,
y: scale)
trans = trans.translatedBy(x: viewWidth * 0.6, y: 0)
navigationController.view.transform = trans

} else {
navigationController.view.transform = .identity
}

}) { (complete) in
if show {
let sideMenuView = UIApplication.shared.keyWindow?.viewWithTag(-253)
sideMenuView?.removeFromSuperview()
}
}
}

关于swift - CGAffineTransform - 使用后像素化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57186932/

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