gpt4 book ai didi

ios - 为选择 View Controller 创建导航栏标题图像会产生奇怪的行为

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

我使用以下函数在选定 View Controller 的导航栏标题位置创建了一个 Logo :

class func setUpLogoOnNavBar(sourceVC: UIViewController) {

dispatch_async(dispatch_get_main_queue(), { () -> Void in

let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 135, height: 90))
imageView.contentMode = .ScaleAspectFit
let image = UIImage(named: "LogoAppHeaderBar.png")
imageView.image = image

sourceVC.navigationItem.titleView = imageView
})
}

通过使用 GCD 将它放在主线程上,当我执行标准的推送转场时,它会导致图像跳到导航栏的左侧,这看起来非常糟糕。当我从下面的函数中删除 GCD 代码时, Logo 跳跃消失了。但是,我得到 This application is modifying the autolayout engine from a background thread,这可能导致引擎损坏和奇怪的崩溃。此外, Logo 不会在某些 View Controller 中加载,因为(我假设)它是不在主线程上执行此操作。我该如何处理这个图像才能在主线程上加载,但在我继续时不会跳转?提前致谢!

最佳答案

为什么在设计 UI 时要使用 GCD?看起来您不是通过网络获取图像,因此布局导航栏不应异步完成。您是否从另一个线程调用 setUpLogoOnNavBar ?你不应该。

关于ios - 为选择 View Controller 创建导航栏标题图像会产生奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36191107/

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