我不能在同一个项目中使用viewDidAppear和viewDidDisappear

时间:2015-05-09 16:09:58

标签: ios swift uiwebview viewdidappear

radarMapUIWebView对象,exitMapButton是其关闭按钮。要访问地图,我使用了隐藏的操作。现在我想在隐藏时添加淡出和淡入动画。我确实淡入但没有淡出。如何在隐藏时添加淡出动画?

func openRadarMap(){
        radarMap.hidden = false
        exitMapButton.hidden = false
        self.radarMap.alpha = 0
        self.exitMapButton.alpha = 0

    }

    override func viewDidAppear(animated: Bool) {

        if radarMap.hidden == false {
        super.viewDidAppear(animated)
        UIView.animateWithDuration(0.5, animations: {
            self.radarMap.alpha = 1.0
            self.exitMapButton.alpha = 1.0
        }) }
    }

    func exitFromMap() {
        exitMapButton.hidden = true
        radarMap.hidden = true
        self.exitMapButton.alpha = 0.0
        self.radarMap.alpha = 0.0
    }



    override func viewDidDisappear(animated: Bool) {
        super.viewDidDisappear(animated)
        UIView.animateWithDuration(0.5, animations: {
            self.radarMap.alpha = 0.0
            self.exitMapButton.alpha = 0.0
        })
    }

    @IBAction func exitMapButtonAction(sender: AnyObject) {
        exitFromMap()
    }



    @IBAction func webView(sender: UIButton) {
        getAd()
       openRadarMap()
        let URL = "http://www.flightradar24.com/41.06,28.94/"
        let requestURL = NSURL(string:URL)
        let request = NSURLRequest(URL: requestURL!)
        radarMap.loadRequest(request)
        //performSegueWithIdentifier("mapView", sender: nil)
    }

2 个答案:

答案 0 :(得分:1)

从视图层次结构中删除视图后,将调用方法viewDidAppear。方法的描述说,

  

通知视图控制器其视图已从视图层次结构中删除。

因此当时视图实际上不可见,我建议您在viewWillDisappear

中编写淡出代码

答案 1 :(得分:-1)

在所有情况下,您都需要致电super。如果您没有为viewDidAppear:拨打超级电话,则无法拨打viewDidDisappear: