简体   繁体   中英

swift UIVisualEffectView with mask autolayout varies by iOS device

I am working with swift UIVisualEffectView with mask option. I am trying to make a blurred UIVisualEffectView masked by UIImageView . I've set autolayout constraints to the views at the storyboard but the result varies through the iOS device. Storyboard, code and results are attached below. I would be glad if anyone help me. I've set all auto layout constraints at the storyboard.(Capture included below) Code is very simple. I've only set blurView.mask = topImageView .

class TestViewController: UIViewController {

    @IBOutlet weak var bottomImageView: UIImageView!
    @IBOutlet weak var topImageView: UIImageView!
    @IBOutlet weak var blurView: UIVisualEffectView!
    override func viewDidLoad() {
        super.viewDidLoad()
        blurView.mask = topImageView
    }

// Still same issue when I move the mask to 'viewDidLayoutSubviews()' method
//
//    override func viewDidLayoutSubviews() {
//        super.viewDidLoad()
//        blurView.mask = topImageView
//    }

}

Storyboard and Code capture

Results depending on iOS versions

--- I've tried to move mask code from viewDidLoad() method to viewDidLayoutSubviews() but it's still same.

Self-solved by the below code. Received a hint from similar issue: 'https://stackoverflow.com/questions/58998541/swift-mask-uiview-constraints-issues/59037761'

override func viewDidAppear() {
    self.setupBlur()
}

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