[英]Custom popup over UITableViewController is swipe-able - how to prevent - Swift
我試圖通過嵌入在UINavigationController中的UITableViewController彈出自定義彈出窗口,但是遇到兩個問題:
請參閱下面的屏幕截圖。
func showProgrssBarPopUp(){
let popUp = self.storyboard?.instantiateViewController(withIdentifier: "uploadPopUp") as! ProgressBarPopUpViewController
self.navigationController?.pushViewController(popUp, animated: true)
}
即使疊加彈出式viewcontroller的alpha值設置為0.5,較低的viewcontroller內容也不可見。
整個彈出式視圖控制器都是可滑動的:
您可以設置背景的Alpha
self.view.backgroundColor = UIColor.white.withAlphaComponent(0.2)
您可以使用modalPresentationStyle
作為overCurrentContext
ProgressBar視圖
let popUp = self.storyboard?.instantiateViewController(withIdentifier: "uploadPopUp") as! ProgressBarPopUpViewController
popUp.modalPresentationStyle = .overCurrentContext
self.present(popUp, animated: true, completion: nil)
只是重寫視圖控制器的出現/關閉方法
class PopUpController: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if animated {
view.backgroundColor = .clear
UIView.animate(withDuration: animationTime) {
self.view.layer.backgroundColor = UIColor.black.withAlphaComponent(0.75).cgColor
}
}
}
override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
if flag {
UIView.animate(withDuration: animationTime, animations: {
self.view.layer.backgroundColor = UIColor.clear.cgColor
}, completion: { (bool) in
super.dismiss(animated: false, completion: completion)
})
} else {
super.dismiss(animated: flag, completion: completion)
}
}
}
采用
let popUp = PopUpController()
popUp.modalPresentationStyle = .overCurrentContext
self.present(popUp, animated: true, completion: nil)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.