删除SubView更快

时间:2016-01-19 19:10:35

标签: ios swift uinavigationbar

在我UIViewController嵌入UINavigationController的主 if let navigationBar = self.navigationController?.navigationBar { let frameDomanda = CGRect(x: navigationBar.frame.width/2 - domandaN.frame.width/2, y: -10, width: domandaN.frame.width, height: navigationBar.frame.height) domandaN.frame = frameDomanda let secondLabel = UILabel(frame: secondFrame) secondLabel.text = "Second" navigationBar.addSubview(domandaN) } 中,我使用该代码向导航栏添加了一个UILabel:

override func viewDidDisappear(animated: Bool) {
    domandaN.removeFromSuperview()
}

但是当我更改Controller时,UILabel已修复。它并没有消失,所以我添加了该代码:

{"content": "Book.xml", "type": "string", "name": "name", "key": 102}
{"content": "D:/XMLexample/Book.xml", "type": "string", "name": "location", "key": 102}
{"content": "xml", "type": "string", "name": "mime-type", "key": 102}
{"content": 4130, "type": "string", "name": "size", "key": 102}
{"content": "Sun Aug 25 07:53:32 2013", "type": "string", "name": "created_date", "key": 102}
{"content": "Wed Jan 23 09:14:07 2013", "type": "string", "name": "modified_date", "key": 102}
{"content": "catalog", "type": "tag", "name": "root", "key": 102}
{"content": "book", "type": "string", "name": "tag", "key": 103} 
{"content": "bk101", "type": {"py/type": "__builtin__.str"}, "name": "id", "key": 103}
{"content": "Gambardella, Matthew", "type": {"py/type": "__builtin__.str"}, "name": "author", "key": 1031} 
{"content": "XML Developer's Guide", "type": {"py/type": "__builtin__.str"}, "name": "title", "key": 1031}
{"content": "Computer", "type": {"py/type": "__builtin__.str"}, "name": "genre", "key": 1031}
{"content": "44.95", "type": {"py/type": "__builtin__.str"}, "name": "price", "key": 1031}
{"content": "2000-10-01", "type": {"py/type": "__builtin__.str"}, "name": "publish_date", "key": 1031}
{"content": "An in-depth look at creating applications with XML.", "type": {"py/type": "__builtin__.str"}, "name": "description", "key": 1031}

它可以工作,但我希望它在按下后退按钮后立即消失。不喜欢这张图片: ("示例"文本稍后消失)

enter image description here

2 个答案:

答案 0 :(得分:0)

您可以使用viewWillDisappear,也不要忘记拨打超级:

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    // you code here
}

答案 1 :(得分:0)

只需将其添加到viewWillDisappear中即可:

override func viewWillDisappear(animated: Bool) {
    domandaN.removeFromSuperview()
}

对于动画参数:

  

如果为true,则视图的消失将被动画化。