简体   繁体   English

UINavigationController:弹出 ViewController Animation 暂停一会儿

[英]UINavigationController: Pop ViewController Animation pause for a while

I pop a viewcontroller with a full screen UIImageView(mode: .scaleAspectFill)我弹出一个带有全屏 UIImageView(mode: .scaleAspectFill) 的视图控制器

when I set ImageView.layer.maskToBounds = false , and pop out the viewcontroller, the pop up animation will pause for a while in the end当我设置ImageView.layer.maskToBounds = false并弹出视图控制器时,弹出的 animation 最后会暂停一段时间

and when turn ImageView.layer.maskToBounds = true everything works fine.当转动ImageView.layer.maskToBounds = true一切正常。

here is the code这是代码

class ImageViewController: UIViewController {
    
    lazy var imageView: UIImageView = {
        let view = UIImageView(image: UIImage(named: "1.jpg"))
        view.contentMode = .scaleAspectFill
        view.layer.masksToBounds = false
        return view
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.addSubview(imageView)
        imageView.frame = view.bounds
    }

}

What is the reason?是什么原因?

Thanks:)谢谢:)

在此处输入图像描述

What is happening is that the image is going beyond the UIImageView 's bounds and outside the ViewController.发生的事情是图像超出了UIImageView的边界和 ViewController 之外。 You can see the pause when the pop animation is finished but the ViewController is not yet dismissed.当弹出 animation 完成但 ViewController 尚未关闭时,您可以看到暂停。

If you want a full screen image it's the UIImageView that should fill the entire screen, but the image inside it should not escape its bounds.如果您想要全屏图像,则UIImageView应该填满整个屏幕,但其中的图像不应超出其范围。

Easiest way to do so is by setting:最简单的方法是设置:

view.autoresizingMask = [.flexibleWidth, .flexibleHeight]

where you are initializing your lazy imageView.你在哪里初始化你的懒惰 imageView。

Remove the masksToBounds property which defaults to false , and you should be done!删除默认为falsemasksToBounds属性,你应该完成了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM