简体   繁体   中英

UINavigationController: Pop ViewController Animation pause for a while

I pop a viewcontroller with a full screen 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

and when turn ImageView.layer.maskToBounds = true everything works fine.

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. You can see the pause when the pop animation is finished but the ViewController is not yet dismissed.

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.

Easiest way to do so is by setting:

view.autoresizingMask = [.flexibleWidth, .flexibleHeight]

where you are initializing your lazy imageView.

Remove the masksToBounds property which defaults to false , and you should be done!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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