Im trying to flip a UIImageView
to its other side to reveal whats behind it. Everything works fine the first flip over, revealing the image behind it. The issue is when i try to flip it back to hide the image. I get an error that its trying to find a nil.Thanks for any help.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var mainLeftView: UIView!
@IBOutlet weak var back: UIImageView!
@IBOutlet weak var front: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
let singleTap = UITapGestureRecognizer(target: self, action: Selector("tappedItem"))
singleTap.numberOfTapsRequired = 1
mainLeftView.addGestureRecognizer(singleTap)
mainLeftView.userInteractionEnabled = true;
mainLeftView.addSubview(front)
}
var showingFront = true;
func tappedItem() {
/* TRIED METHOD NUMBER ONE
var views: (front: UIImageView, back: UIImageView)
if ((self.front.superview) != nil){
views = (front: self.front, back: self.back)
} else{
views = (front: self.back, back: self.front)
}
UIView.transitionFromView(views.front, toView: views.back, duration: 1.0, options:UIViewAnimationOptions.TransitionFlipFromRight , completion: nil)
*/
// METHOD NUMBER TWO
if (showingFront){
UIView.transitionFromView(front, toView: back, duration: 0.5, options: UIViewAnimationOptions.TransitionFlipFromRight, completion: nil)
showingFront = false;
}
else{
UIView.transitionFromView(back, toView: front, duration: 0.5, options: UIViewAnimationOptions.TransitionFlipFromLeft, completion: nil)
showingFront = true;
}
}