2017-03-02 15 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

相关问题