繁体   English   中英

UITableViewController上的自定义弹出式窗口可滑动-如何防止-Swift

[英]Custom popup over UITableViewController is swipe-able - how to prevent - Swift

我试图通过嵌入在UINavigationController中的UITableViewController弹出自定义弹出窗口,但是遇到两个问题:

  1. 我通过为弹出窗口的UIViewcontroller的背景色指定一个alpha值来确定不透明度。
  2. 弹出窗口的UIViewcontroller是可滑动的。 如果我在屏幕上做出从左到右的手势,则可以按下弹出窗口。 如何防止它表现出这种现象? 我正在尝试显示文件上传进度,因此不能弹出弹出窗口很重要。

请参阅下面的屏幕截图。

    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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM