繁体   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