[英]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.