【问题标题】:Background Image causing animated popViewController delay/lag背景图像导致动画 popViewController 延迟/滞后
【发布时间】:2020-10-30 19:13:24
【问题描述】:

弹出视图控制器时动画出现延迟。

我收到延迟的原因是因为我有背景图片。

override func viewDidLoad() {
        super.viewDidLoad()
        
       setBackgroundImage()
        
    }

@IBAction func navigationButton(_ sender: Any) {
        
        print("navigation button presssed")
        self.navigationController?.popViewController(animated: true)
    }

func setBackgroundImage() {

        let backgroundImage = UIImageView(frame: UIScreen.main.bounds)
        backgroundImage.image = UIImage(named: "RewardsBackgroundONLY")
        backgroundImage.contentMode = UIView.ContentMode.scaleAspectFill
        self.view.insertSubview(backgroundImage, at: 0)
    }

如何防止设置背景图片时出现延迟。

我也试过在主线程上弹出视图控制器,还是不行。

【问题讨论】:

    标签: ios swift viewcontroller


    【解决方案1】:

    可能是您的图片太大,内容模式backgroundImage.contentMode = UIView.ContentMode.scaleAspectFill 导致了这种行为。

    你有两种方法可以解决这个问题。

    1. 更改 UIView.ContentMode 值并检查是否适合您。试试scaleToFillscaleAspectFit

    2. 调整图片大小以适合您的应用。

    【讨论】:

    • 奇怪,我从来没有遇到过 scaleAspectFill 延迟我的应用程序
    • @aheze 实际上这不会导致滞后,但似乎是滞后。这是导航控制器中的奇怪行为
    • @RamiresNascimento 明白了,很奇怪。
    猜你喜欢
    • 2012-09-08
    • 1970-01-01
    • 1970-01-01
    • 2018-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-23
    相关资源
    最近更新 更多