Ios 如何将ImageView包含到自定义序列中?

Ios 如何将ImageView包含到自定义序列中?,ios,swift,xcode,Ios,Swift,Xcode,我正在尝试创建一个自定义的序列,其中动画的顺序 第一个UIViewController->ImageView->第二个UIViewController 我的代码可以工作,但由于某种原因,ImageView是黑色的。我尝试过使用各种图像和文字图像源,但仍然是黑色的 为了更好地理解,这里有一些图片- 1(第一个UIViewController被ImageView替换) 2(当ImageView被第二个UIViewController替换时) secondView从未出现,因为您从未将其插入到界面

我正在尝试创建一个自定义的序列,其中动画的顺序

第一个UIViewController->ImageView->第二个UIViewController

我的代码可以工作,但由于某种原因,ImageView是黑色的。我尝试过使用各种图像和文字图像源,但仍然是黑色的

为了更好地理解,这里有一些图片-

1(第一个UIViewController被ImageView替换)

2(当ImageView被第二个UIViewController替换时)


secondView
从未出现,因为您从未将其插入到界面中


(我认为您的代码总体上是完全错误的-如果您想要自定义过渡,您应该编写适当的自定义过渡动画代码。但这回答了为什么图像视图是“黑色”的问题-它不是黑色的,它是完全没有的。)

这几乎是一个标准的segue吗?我所说的是prepare(用于segue:sender:)和performsgue(带有标识符:sender:)。如果是的话,请张贴代码。谢谢。我想我要找的答案会接近你给我的答案。整个动画应该发生在0.4中,im使用的图像将不同的渐变混合在一起。你能推荐我正确的编码方法吗?嗨,正确的方法就是我在回答中所说的。Apple为编写自定义视图控制器转换动画提供了完整的API。你应该用它。有关这方面的初始信息,请参阅WWDC 2013视频会话218。
/**
 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)
        }
    }

}