[英]Custom popup over UITableViewController is swipe-able - how to prevent - Swift
I am trying to make a custom pop up over a UITableViewController that is embedded in a UINavigationController but I am experiencing two problems: 我试图通过嵌入在UINavigationController中的UITableViewController弹出自定义弹出窗口,但是遇到两个问题:
Please see screen shot below. 请参阅下面的屏幕截图。
func showProgrssBarPopUp(){
let popUp = self.storyboard?.instantiateViewController(withIdentifier: "uploadPopUp") as! ProgressBarPopUpViewController
self.navigationController?.pushViewController(popUp, animated: true)
}
The lower viewcontroller content is not viewable, even though alpha value of overlaying popup viewcontroller is set to 0.5: 即使叠加弹出式viewcontroller的alpha值设置为0.5,较低的viewcontroller内容也不可见。
The entire viewcontroller for popup is swipe-able: 整个弹出式视图控制器都是可滑动的:
You can set alpha of background 您可以设置背景的Alpha
self.view.backgroundColor = UIColor.white.withAlphaComponent(0.2)
You can Present ProgressBar View with modalPresentationStyle
as overCurrentContext
您可以使用
modalPresentationStyle
作为overCurrentContext
ProgressBar视图
let popUp = self.storyboard?.instantiateViewController(withIdentifier: "uploadPopUp") as! ProgressBarPopUpViewController
popUp.modalPresentationStyle = .overCurrentContext
self.present(popUp, animated: true, completion: nil)
Just override view controller's appear/dismiss method 只是重写视图控制器的出现/关闭方法
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)
}
}
}
Use 采用
let popUp = PopUpController()
popUp.modalPresentationStyle = .overCurrentContext
self.present(popUp, animated: true, completion: nil)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.