gpt4 book ai didi

ios - 如何将 ImageView 包含到自定义 Segue 中?

转载 作者:行者123 更新时间:2023-11-30 12:38:31 25 4
gpt4 key购买 nike

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

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

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

这里有一些图片可以更好地理解-

1 (As the first UIViewController is replaced by the ImageView)

First VC

2 (As the ImageView is replaced by the second 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)
}
}

}

最佳答案

secondView 永远不会出现,因为您任何时候都不会将其插入界面中。

(我将您的代码描述为完全错误的 - 如果您想要自定义过渡,您应该编写正确的自定义过渡动画代码。但这回答了为什么 ImageView 是“黑色”的问题 - 它不是不是黑色,它完全不存在。)

关于ios - 如何将 ImageView 包含到自定义 Segue 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42562856/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com