斯威夫特:摆脱“昏暗”

时间:2016-09-16 17:17:44

标签: ios swift

我一直在关注本教程:http://www.totem.training/swift-ios-tips-tricks-tutorials-blog/ux-chops-dim-the-lights

但是我稍微编辑了一下,以便我可以指定不同的Segues并以编程方式进行编辑。

关闭弹出视图时会出现问题。当我关闭它时,背景暗淡停留在那里:

enter image description here

我对项目文件做了什么:

文件:(https://github.com/TotemTraining/DimBackground.git

1)删除了那里的Segue

2)为名为 clickedButton 的按钮创建IBAction

3)从第一个VC到第二个创建新Segue命名为Segue testSegue

4)为IBAction添加了此代码:

@IBAction func clickedButton(sender: AnyObject) {
    performSegueWithIdentifier("testSegue", sender: self)
}

5)将 prepareForSegue 更改为:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if (segue.identifier == "testSegue") {
    dim(.In, alpha: dimLevel, speed: dimSpeed)
    }
}

现在,当我运行它时,它会以所需的方式显示弹出窗口,但是当我点击关闭时它将其移除但是在那里留下了“Dim”。谁能明白为什么?

视图将有几个段落,我只想让其中一些具有这种“暗淡”效果。

编辑:

如果我现在取出 if(segue.identifier ==“testSegue”),那么:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    //if (segue.identifier == "testSegue") {
    dim(.In, alpha: dimLevel, speed: dimSpeed)
    //}
}

它按预期工作,所以它与它有关吗?

1 个答案:

答案 0 :(得分:2)

听起来你的放松并没有被调用以便调暗。你设置了一个断点来确定吗?此外,如果您使用Xcode 8,有一个奇怪的错误与展开segue名称。它们自动在末尾添加了“WithSegue:”,因此请仔细检查它是否在Interface Builder中正确标记。