Ich versuche, zwei UIViews
Flip. Ich habe versucht, UIView
programmgesteuert zu verwenden und es funktioniert perfekt. Aber wenn ich versuche, UIView
zu spiegeln, dass ich in storyboard
erstellte, funktioniert es nicht, erstes Mal, das es UIView kippt, aber zum zweiten Mal kippt es leer UiViews
? Irgend jemand hat eine Idee, gibt es einen Fehler in meinem Code?UIViewAnimationOptions.TransitionFlipFromLeft nicht UIView zweites Mal zeigt
In diesem Bild links oben Debug view Hierarchy
Bild ist vor Button Animieren und links unten Debug view Hierarchy
Bild nach dem Animieren ist.
Wenn das zweite Mal, dass ich die UIView
animieren es wie dieses Bild unten Flip.
class ViewController: UIViewController {
@IBOutlet var container: UIView!
@IBOutlet var blueSquare : UIView!
@IBOutlet var redSquare : UIView!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func animateButtonTapped(sender: AnyObject) {
// create a 'tuple' (a pair or more of objects assigned to a single variable)
var views : (frontView: UIView, backView: UIView)
if ((self.redSquare.superview) != nil) {
views = (frontView: self.redSquare, backView: self.blueSquare)
}
else {
views = (frontView: self.blueSquare, backView: self.redSquare)
}
// set a transition style
let transitionOptions = UIViewAnimationOptions.TransitionFlipFromLeft
// with no animation block, and a completion block set to 'nil' this makes a single line of code
UIView.transitionFromView(views.frontView, toView: views.backView, duration: 1.0, options: transitionOptions, completion: nil)
}
}
Programmatically Dieser Code ist perfekt funktioniert.
let container = UIView()
let redSquare = UIView()
let blueSquare = UIView()
override func viewDidLoad() {
super.viewDidLoad()
// set container frame and add to the screen
self.container.frame = CGRect(x: 60, y: 60, width: 200, height: 200)
self.view.addSubview(container)
// set red square frame up
// we want the blue square to have the same position as redSquare
// so lets just reuse blueSquare.frame
self.redSquare.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
self.blueSquare.frame = redSquare.frame
// set background colors
self.redSquare.backgroundColor = UIColor.redColor()
self.blueSquare.backgroundColor = UIColor.blueColor()
// for now just add the redSquare
// we'll add blueSquare as part of the transition animation
self.container.addSubview(self.redSquare)
}
@IBAction func animateButtonTapped(sender: AnyObject) {
// create a 'tuple' (a pair or more of objects assigned to a single variable)
var views : (frontView: UIView, backView: UIView)
if((self.redSquare.superview) != nil){
views = (frontView: self.redSquare, backView: self.blueSquare)
}
else {
views = (frontView: self.blueSquare, backView: self.redSquare)
}
// set a transition style
let transitionOptions = UIViewAnimationOptions.TransitionFlipFromLeft
// with no animation block, and a completion block set to 'nil' this makes a single line of code
UIView.transitionFromView(views.frontView, toView: views.backView, duration: 1.0, options: transitionOptions, completion: nil)
}
UPDATE
var check = true
@IBAction func animateButtonTapped(sender: AnyObject) {
// create a 'tuple' (a pair or more of objects assigned to a single variable)
var views : (frontView: UIView, backView: UIView)
if (check == true) {
views = (frontView: self.redSquare, backView: self.blueSquare)
check = false
}
else {
views = (frontView: self.blueSquare, backView: self.redSquare)
check = true
}
// set a transition style
let transitionOptions : UIViewAnimationOptions = [UIViewAnimationOptions.TransitionFlipFromLeft, UIViewAnimationOptions.ShowHideTransitionViews]
// with no animation block, and a completion block set to 'nil' this makes a single line of code
UIView.transitionFromView(views.frontView, toView: views.backView, duration: 1.0, options: transitionOptions, completion: nil)
}
Danke @Eugene H, ich füge das hinzu, aber jetzt zeigt es mir, dass der Fehler 'Wert des Typs '[UIViewAnimationOptions]' nicht zum erwarteten Argumenttyp 'UIViewAnimationOptions' in der letzten Zeile konvertieren kann. Kannst du es bitte reparieren? – ZAFAR007
Oh, muss ein Problem mit Ihrer Typdeklaration sein. Siehe oben Bearbeiten mit meiner Deklaration –
Um klar zu sein, ist UIViewAnimationOptions ein OptionSetType. Weitere Informationen finden Sie unter http: //www.swift-studies.com/blog/2015/6/17/exploring-swift-20-optionsettypes –