簡體   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