2017-03-02 54 views
0

我試圖在動畫的順序去如何將ImageView添加到自定義Segue中?

1 UIViewController中創建一個自定義賽格瑞 - > ImageView的 - >第2的UIViewController

我作品中的代碼,但由於某些原因,ImageView的是黑色的。我試過使用各種圖像和文字圖像來源,但它仍然是黑色的。

這裏的一些圖片,更好understanding-

1(作爲第一UIViewController中由ImageView的替換)

First VC

2(作爲ImageView的是由第二個UIViewController取代)

Second VC

/** 
This segue transitions by dragging the destination UIViewController in from the right and replacing the old UIViewController by pushing it off to the left. This Segue also contains an ImageView that is between the two UIViewControllers. 
*/ 
class CustomSegue2: UIStoryboardSegue { 

    override func perform() { 

     // Assign the source and destination views to local variables. 
     let firstView = self.source.view as UIView! 
     let secondView = UIImageView() 
     let thirdView = self.destination.view as UIView! 

     // Get the screen width and height. 
     let width = UIScreen.main.bounds.size.width 
     let height = UIScreen.main.bounds.size.height 

     // Set properties of secondView 
     secondView.frame = CGRect(x: width, y: 0, width: width, height: height) 
     secondView.contentMode = UIViewContentMode.scaleToFill 
     secondView.image = #imageLiteral(resourceName: "orangeRedGradient_MESH_tealGreenGradient") 

     // Specify the initial position of the destination view. 
     let rect = CGRect(x: width + width, y: 0.0, width: width, height: height) 
     thirdView?.frame = rect 

     // Access the app's key window and insert the destination view above the current 
     let window = UIApplication.shared.keyWindow 
     window?.insertSubview(thirdView!, aboveSubview: firstView!) 


     // Animation the transition. 
     UIView.animate(withDuration: 10, animations: {() -> Void in 
      firstView?.frame = firstView!.frame.offsetBy(dx: -width-width, dy: 0.0) 
      secondView.frame = secondView.frame.offsetBy(dx: -width-width, dy: 0.0) 
      thirdView?.frame = thirdView!.frame.offsetBy(dx: -width-width, dy: 0.0) 
     }) { (Finished) -> Void in 
      self.source.present(self.destination, animated: false, completion: nil) 
     } 
    } 

} 
+0

這是非常標準的賽格?我正在談論*準備(對於Segue:發件人:)*和* performSegue(withIdentifier:發件人:)*。如果是這樣,請發佈該代碼。謝謝。 – dfd

回答

0

secondView,因爲在任何時候你將其插入接口永遠不會出現。如果你想自定義轉換,你應該編寫適當的自定義轉換動畫代碼,但是這回答了爲什麼圖像視圖是「黑色」的問題 - 它是不是黑色,它是完全缺席。)

+0

我想我正在尋找的答案將接近你給我的答案。整個動畫應該在0.4中發生,圖像im使用不同的漸變混合在一起。你能推薦我用正確的方式來編碼嗎? –

+0

嗨 - 正確的方法是我在我的答案中說的。 Apple提供了一個用於編寫自定義視圖控制器轉換動畫的完整API。你應該使用它。有關此初始信息,請參閱WWDC 2013視頻會話218。 – matt

相關問題