###前提・実現したいこと
storyboard上の複数のImage View全てをドラッグ終了したあとに画面遷移をしたいです。
Image Viewはドラッグをするとアニメーションで消えるようにしています。
###該当のソースコード
import UIKit class ViewController: UIViewController { //ドラッグのカウント var flg = 0 //フェードアウトが完了したら実行 func fadeoutAndRemove(_ view:UIView) { UIView.animate( withDuration: 3.0, delay: 0, options: [.curveEaseInOut], animations: { view.removeFromSuperview() }) } @IBAction func drag01(_ sender: UIPanGestureRecognizer) { //ドラッグしているビュー let fl01 = sender.view! //透明度 fl01.alpha = 1.0 //指の座標に合わせる fl01.center = sender.location(in: self.view) //フェードアウトのアニメーション UIView.animate( withDuration: 3.0, delay: 0, options: [.curveEaseInOut], animations: { //移動する fl01.center.y += 1 //消える fl01.alpha = 0.0 }, completion: {(finished: Bool) in //終わったら self.fadeoutAndRemove(fl01) //ドラッグのカウント1プラス self.flg += 1 print(self.flg) }) } @IBAction func drag02(_ sender: UIPanGestureRecognizer) { //ドラッグしているビュー let fl02 = sender.view! //透明度 fl02.alpha = 1.0 //指の座標に合わせる fl02.center = sender.location(in: self.view) //フェードアウトする UIView.animate( withDuration: 3.0, delay: 0, options: [.curveEaseInOut], animations: { //移動する fl02.center.y += 1 //消える fl02.alpha = 0.0 }, completion: {(finished: Bool) in //終わったら self.fadeoutAndRemove(fl02) //ドラッグのカウント1プラス self.flg += 1 print(self.flg) }) } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
###試したこと
現状は、ドラッグが終了した時の判別方法が分からず、悩んでおります。
判別方法として考えたのは、各IBActionにflgをつけてImage Viewの個数分のカウントができるかと思ったのですが、アニメーションをしているせいかアニメーションが終わるまでflgが加算されてしまいました。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/20 06:58