How to arrange animation order properly in Swift language for ios? -
I have to realize such an effect: a pile of card (UIView) (0,0) to (100,100) ) One by one; After the last card is over, all the cards come back again (0,0) after one I wrote the code written below, but the effect is not correct Please help me understand that the problem is where is.
Import UIKit class card: UIView {var name: string = "" init (name: string) {super.init (frame: CGRtechMake (0, 0, 100, 100)) .name = name self.layer.borderColor = UIColor.blueColor () CGColor self.layer.borderWidth = 0.3}} Class ViewController:. UIViewController {var cardGroup: Card [] = [] Start @IBOOTlet var: UIButton! Override Funk Viewedload () {super.viewDidLoad ()} @Ibation Funk Start () {var Cardorder = ["HeartSyncS", "HeartSewen", "Heart Eite", "Hartinine", "Hearttone", "DiamondJack", "ClubQueen "," SpadeKing "," HeartAce "] for (Var I = 0; I & lt; cardOrder.count; ++ i) {var card = card (name: cardOrder [i]) cardGroup.append (card) self .view. AddSubview (Card Group [i]) UIView.animateWithDuration (0.5, Delay: 0.5, Options: UIViewAnimationOptions.CurveEaseOut, Animation: {() -> empty in self.cardGroup [i]. Center = CGPoint (x: 100 + 3 * I, y: 100 + 3 * i)}, Completeness: {(Bull) -> //.sound.stop ()}}} self.nextAnimation ()} func nextAnimation () {for (var i = 0; i Zero in Self Cord Group [i] . {Center = CP point (X: 0, Y: 0)}, complete: {(BULL) -> gtc: //sound.stop ()})}} Override function didReceiveMemoryWarning () in zero {super.didReceiveMemoryWarning () }}
self.nextAnimation ()
in completion handler
@IBAction function start () {var CardOrder = ["HeartSeven"] "HeartSeven", "HeartEeven", "HeartNine", "HeartTen", "DiamondJack" "(ClubQueen for Brides," "SpadeKing", "HeartAce"] = 0 ; I & lt; CardOrder.count; ++ i) {var card = card (name: card order [i]) card group.append (card) self.view.addSubview (card group [i]) UIView.animateWithDuration (0.5, delay: 0.5, option: UIViewAnimationOptions. CurveEaseOut, Animation: {Zero: [i] .center = CGPoint (x: 100 + 3 * i, y: 100 + 3 * i)}, perfection: {(Bull) -> Gt; zero in // sound.s top () self.nextAnimation ()})}}
Comments
Post a Comment