gpt4 book ai didi

插入 View Controller 时快速背景颜色

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

我有两个白色 View Controller 。当我尝试插入第二个 View Controller 时,我注意到灰色背景(基本上它在过渡期间改变了 alpha 值)。有什么办法可以禁用这种淡入淡出吗?我只想我的背景是白色的enter image description here

最佳答案

使用 UIViewControllerAnimatedTransitioning 绝对是“正确”的方法,但看来你真的不想使用它。

如果你想“破解”它,那么 swizzling 就是最佳选择。

这是 UIView 的扩展,可防止显示底层类 _UIParallaxDimmingView

extension UIView {
static func preventDimmingView() {
guard let originalMethod = class_getInstanceMethod(UIView.self, #selector(addSubview(_:))), let swizzledMethod = class_getInstanceMethod(UIView.self, #selector(swizzled_addSubview(_:))) else { return }
method_exchangeImplementations(originalMethod, swizzledMethod)
}

static func allowDimmingView() {
guard let originalMethod = class_getInstanceMethod(UIView.self, #selector(addSubview(_:))), let swizzledMethod = class_getInstanceMethod(UIView.self, #selector(swizzled_addSubview(_:))) else { return }
method_exchangeImplementations(swizzledMethod, originalMethod)
}

@objc func swizzled_addSubview(_ view: UIView) {
let className = "_UIParallaxDimmingView"
guard let offendingClass = NSClassFromString(className) else { return swizzled_addSubview(view) }
if (view.isMember(of: offendingClass)) {
return
}
swizzled_addSubview(view)
}
}

我建议按照以下方式使用它:

class SomeViewController: UIViewController {

func transition(to viewController: UIViewController) {
navigationController?.delegate = self
navigationController?.pushViewController(viewController, animated: true)
}
}


extension SomeViewController: UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
UIView.preventDimmingView()
}

func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
UIView.allowDimmingView()
}
}

当然,如果您希望它能够通过 App Store 审核,您可能会被标记为 "_UIParallaxDimmingView" 字符串。我建议改为从字节数组初始化它:

let className = String(bytes: [95, 85, 73, 80, 97, 114, 97, 108, 108, 97, 120, 68, 105, 109, 109, 105, 110, 103, 86, 105, 101, 119], encoding: .utf8)!

gif

关于插入 View Controller 时快速背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59473448/

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