2017-02-26 106 views
0

我正在創建一個動畫,它將圖像和標籤從左側移到視圖的中央。無法隱藏動畫後的視圖

  1. imageLogo.isHidden = true當應用程序運行
  2. labelLogo不隱藏不顯示在所有對我一直在閱讀教程視圖

,但我看不出有什麼毛病我碼。

let paymentLogo = UIImage(named: "paymentImage") 
var imageLogo:UIImageView! 
var overlayView = UIView() 
var logoAppeared:Bool! 
let labelLogo = UILabel() 

override func viewDidLayoutSubviews() { 
    //move picture off the screen here 

    self.imageLogo = UIImageView(image:paymentLogo) 
    imageLogo.frame = CGRect(x: 0, y: 0, width: 100, height: 100) 
    imageLogo.center.x -= 400 
    self.view.addSubview(imageLogo) 

    self.labelLogo.frame = 
     CGRect(x: 0, y: 0, width: 200, height: 21) 
    self.labelLogo.center.x -= 400 
    self.labelLogo.text = "Booking Completed" 
    self.labelLogo.textAlignment = .center 
    self.view.addSubview(labelLogo) 
} 

override func viewDidAppear(_ animated: Bool) { 
    UIView.animate(withDuration: 2.0, delay: 0.1, options: [], animations: { 
     //animate paymentCompletedLogo 
     self.overlayView = UIView(frame: self.view.frame) 
     self.overlayView.backgroundColor = UIColor.black 
     self.overlayView.alpha = 0.4 

     //animate labelLogo 
     self.labelLogo.frame = CGRect(x: self.view.center.x, y: 90, width: 200, height: 21) 
     self.labelLogo.backgroundColor = UIColor.gray 
     self.labelLogo.text = "Booking Completed" 
     self.labelLogo.textColor = .black 
     self.labelLogo.textAlignment = .center 

     //animate imageLogo 
     self.imageLogo.frame = 
      CGRect(x: self.view.center.x,y: self.view.center.y,width: 100,height: 100) 

     self.view.addSubview(self.overlayView) 
     self.view.addSubview(self.imageLogo) 
     self.view.addSubview(self.labelLogo) 
    }) { finished in 
     self.overlayView.isHidden = true 
     self.imageLogo.isHidden = true //it is not hidden in simulator 

     self.logoAppeared = true 
    } 
} 

回答

3

我試圖從動畫方法中刪除以下代碼,它工作正常。 您正試圖在動畫方法中添加子視圖。 imageLogo和labelLogo都已準備好添加到視圖中。

self.view.addSubview(self.overlayView) 
    self.view.addSubview(self.imageLogo) 
    self.view.addSubview(self.labelLogo)