To achieve a cross-fade by merely adding a subview, try UIView.transition(with:duration:options:animations:completion:)
Add your view during the animation block.
A quick playground:
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
override func loadView() {
let view = UIView()
view.backgroundColor = .white
let label = UILabel()
label.frame = CGRect(x: 150, y: 200, width: 200, height: 20)
label.text = "Hello World!"
label.textColor = .black
view.addSubview(label)
self.view = view
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let orangeView = UIView(frame: CGRect(origin: CGPoint(x: view.bounds.midX, y: view.bounds.midY), size: CGSize(width: 100, height: 100)))
orangeView.backgroundColor = .orange
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(300)) {
UIView.transition(with: self.view, duration: 0.6, options: .transitionCrossDissolve, animations: {
self.view.addSubview(orangeView)
}) { _ in
}
}
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()