I'm trying to do a simple flip animation between two views in a Playground using UIView.transitionFromView. As described in this question, older versions of Xcode simply required the option "Run in Full Simulator" to be selected, but that is no longer available in Playground Settings under Platform for Xcode 7.1.
In my working example, the bottom view is always immediately shown. The transition is performed, but with any animation:
import UIKit
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
func flipFrontToBack(frontView: UIView, backView: UIView) {
let transitionOptions = UIViewAnimationOptions.TransitionFlipFromLeft
var views : (frontView: UIView, backView: UIView)
views = (frontView: frontView, backView: backView)
UIView.transitionFromView(views.frontView,
toView: views.backView,
duration: 2.0,
options: transitionOptions,
completion: { _ in
})
}
func smallSquare(backgroundColor: UIColor, borderColor: UIColor) -> UIView {
let bounds = CGRect(x: 50, y: 50, width: 50, height: 50)
let view = UIView(frame: bounds)
view.backgroundColor = backgroundColor
view.layer.borderColor = borderColor.CGColor
view.layer.borderWidth = 5
view.layer.cornerRadius = 10
return view
}
func makeView() -> UIView {
let bounds = CGRect(x: 0, y: 0, width: 400, height: 200)
let view = UIView(frame: bounds)
view.backgroundColor = UIColor.lightGrayColor()
view.layer.borderColor = UIColor.purpleColor().CGColor
view.layer.borderWidth = 5
view.layer.cornerRadius = 10
return view
}
let view = makeView()
var frontCard = smallSquare(UIColor.blackColor(), borderColor: UIColor.whiteColor())
var backCard = smallSquare(UIColor.whiteColor(), borderColor: UIColor.redColor())
view.addSubview(backCard)
view.addSubview(frontCard)
XCPlaygroundPage.currentPage.liveView = view
flipFrontToBack(frontCard, backView: backCard)
My code works in my project in Xcode. I'm simply trying to migrate it to a Playground so I can prototype some additional changes. By commenting out the ** flipFrontToBack()** method, you can see the unflipped and "flipped" image. So, I get the flip, but no animation.