私は比較的プログラミングが新しく、現在3つ(可能な場合はそれ以上)のビューコントローラを使ってアプリケーションを構築しようとしています。私はチュートリアル(https://www.youtube.com/watch?v=B9sH_VxPPo4&t=505s)を行って、カスタムボタンを押した後に2つのView Controllerの間でアニメーションを学んだ。これはすべて完璧に機能しました。SWIFT 3のボタンで3つ以上のビューコントローラ間のトランジションをアニメーション化する方法は?
しかし、私は別のビューコントローラ(ThirdViewController)と2番目のボタン(showThirdVCButton)を実装しようとしています。
トランジションは両方のボタンに対して完全に機能しますが、アニメーションは標準のアニメーションに戻されます。
これは最初のビューコントローラでは私のコードです:
import UIKit
class ViewController: UIViewController, UIViewControllerTransitioningDelegate {
@IBOutlet weak var showSecondVCButton: UIButton!
@IBOutlet weak var showThirdVCButton: UIButton!
let transition = CircularTransition()
override func viewDidLoad() {
super.viewDidLoad()
//I customise my buttons here
showSecondVCButton.layer.cornerRadius = showSecondVCButton.frame.size.width/2
showThirdVCButton.layer.cornerRadius = showSecondVCButton.frame.size.width/2
}
//The destination for each button is declared here and the animation style
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "secondVCSegue" {
let secondVC = segue.destination as! SecondViewController
secondVC.transitioningDelegate = self
secondVC.modalPresentationStyle = .custom
}
if segue.identifier == "thirdVCSegue" {
let thirdVC = segue.destination as! ThirdViewController
thirdVC.transitioningDelegate = self
thirdVC.modalPresentationStyle = .custom
}
}
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
transition.transitionMode = .present
if showSecondVCButton.isTouchInside == true {
transition.startingPoint = showSecondVCButton.center
transition.circleColor = showSecondVCButton.backgroundColor!
}
if showThirdVCButton.isTouchInside == true {
transition.startingPoint = showThirdVCButton.center
transition.circleColor = showThirdVCButton.backgroundColor!
}
return transition
}
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
transition.transitionMode = .dismiss
if showSecondVCButton.isTouchInside == true {
transition.startingPoint = showSecondVCButton.center
transition.circleColor = showSecondVCButton.backgroundColor!
}
if showThirdVCButton.isTouchInside == true {
transition.startingPoint = showThirdVCButton.center
transition.circleColor = showThirdVCButton.backgroundColor!
}
return transition
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
はあなたの助けをありがとう!
あなたが追加しました'if segue.identifier ==" thirdVCSegue "{...}'コード内のブレークポイントにアクセスしていることを確認しますか? segueの識別子にエラーがあると、コードが実行されなくなる可能性があります。 – Rob