0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

BubbleTransitionをStoryboardなしで実装する方法

Posted at

いい感じのアニメーションを実装したくてライブラリを探していたところ、良いのを見つけました。
andreamazz/BubbleTransition

が、とりあえずREADMEどおりにやっても画面遷移のアニメーションが変わりません。
中身を見てみるとStoryboardを使用する前提で作られてるみたいでした。

問題点

Storyboardなしでアプリを作る練習をしている自分としては、なんとかして使いたい

prepareメソッド

コードを見た感じAnimationの動き自体は問題ないが、反応していない。
「何をトリガーにアニメーションを動かしてるだろ」という視点で調べていくうちに

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {    
}

この**「segueが動作することをViewControllerに通知する」**メソッドがトリガーになってるのに気づきました。
UIViewControllerのprepareメソッドについて - emahiro/b.log

【推測】
Storyboardなしで画面遷移を実装した場合、segueが動作しないのではないか

解決策

このメソッドの中身をUIButtonのactionに入れてしまう

@objc func tappedActionButton(_ sender: UIButton) {
        let modalViewController = ModalViewController()
        modalViewController.transitioningDelegate = self
        modalViewController.modalPresentationStyle = .custom
        modalViewController.modalPresentationCapturesStatusBarAppearance = true
        modalViewController.interactiveTransition = interactiveTransition
        
        present(modalViewController, animated: true, completion: nil)
  }

もっといい方法があるかと思いますが、とりあえず希望のAnimationは実装できました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?