簡體   English   中英

以模態呈現的UIViewController的背景顏色隨機變化

[英]Background Color Randomly Changes of UIViewController presented Modally

因此,我有一個UIViewController (AViewController),該UIViewController具有一個以模態呈現另一個UIViewController(BViewController)的UIButton。 BViewController具有使AViewController模糊的UIVisualEffectView。 在情節提要中,我將背景色設置為以下內容的0%不透明度:BViewController的視圖以及UIVisualEffectView及其視圖。 因此,除了應該具有模糊效果之外,它應該是完全透明的。

在大多數情況下,這可以按預期進行。 但是,大約3分之1(但隨機,即我找不到模式)的ViewController的背景是深灰色而不是清晰的。 而且它不是透明的。

我試圖以編程方式確保顏色清晰。 如果我將背景(BViewController和UIVisualEffectView及其視圖的背景)設置為viewDidLoad中的clearColor,則沒有任何變化,即,每4次中有3次起作用。 但是,如果我在viewDidAppear中設置背景,那么它每次都會變成深灰色的確切顏色,而不是每次都不透明(而不是3次1遍)。

代碼簡單明了,UIViewControllers在情節提要中設置。

在AViewController中

var aViewController = storyboard!.instantiateViewControllerWithIdentifier("AViewController") as! 

self.presentViewController(aViewController, animated: false, completion: nil)

在BViewController中

self.dismissViewControllerAnimated(false, completion: nil)

**編輯:使用XCODE簡化測試項目以重復發行**

這給了我9/10倍的深灰色背景-使我意識到我以前從未提出過模態UIViewController。

BViewController

class BViewController: UIViewController {
    @IBAction func exit(sender: AnyObject) {
        self.dismissViewControllerAnimated(false, completion: nil)
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

AViewController

class AViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    @IBAction func present(sender: AnyObject) {
        var bViewController = storyboard!.instantiateViewControllerWithIdentifier("bViewController") as! BViewController

        self.presentViewController(bViewController, animated: false, completion: nil)

    }
}

與Segue建立聯系

據我所知,這是因為每當您向視圖控制器提供一個序列時,它就會通過它所連接的視圖控制器呈現出來,並且也僅放置在當前堆棧中,即ViewControllerA所在的堆棧中。

在沒有連接的情況下,即初始化ViewController

但是,當您初始化視圖控制器(即ViewControllerB)時,它將被加載到新堆棧中,因此在其下方找不到任何視圖控制器,因此在將ViewControllerB的主視圖的顏色設置為CLEAR時,它會顯示深灰色或黑色顏色。

//我希望我能夠傳達自己的信息並對您有所幫助。 快樂編碼:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM