我試圖在動畫的順序去如何將ImageView添加到自定義Segue中?
1 UIViewController中創建一個自定義賽格瑞 - > ImageView的 - >第2的UIViewController
我作品中的代碼,但由於某些原因,ImageView的是黑色的。我試過使用各種圖像和文字圖像來源,但它仍然是黑色的。
這裏的一些圖片,更好understanding-
1(作爲第一UIViewController中由ImageView的替換)
2(作爲ImageView的是由第二個UIViewController取代)
/**
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)
}
}
}
這是非常標準的賽格?我正在談論*準備(對於Segue:發件人:)*和* performSegue(withIdentifier:發件人:)*。如果是這樣,請發佈該代碼。謝謝。 – dfd