Bringing a subview to be in front of all other views

前端 未结 8 1905
走了就别回头了
走了就别回头了 2020-12-07 13:24

I am working on integrating an ad provider into my app currently. I wish to place a fading message in front of the ad when the ad displays but have been completely unsuccess

8条回答
  •  悲哀的现实
    2020-12-07 13:34

    Let me make a conclusion. In Swift 5

    You can choose to addSubview to keyWindow, if you add the view in the last. Otherwise, you can bringSubViewToFront.

    let view = UIView()
    UIApplication.shared.keyWindow?.addSubview(view)
    UIApplication.shared.keyWindow?.bringSubviewToFront(view)
    

    You can also set the zPosition. But the drawback is that you can not change the gesture responding order.

    view.layer.zPosition = 1
    

提交回复
热议问题