Help us understand the problem. What is going on with this article?

上から下への画面遷移アニメーション

More than 1 year has passed since last update.

概要

defaultでのsegueのアニメーションが下から上に画面が出るものだったので、戻るときはその逆である上から下のアニメーションを実装したいと思い、実装してみた

コード

TopToBottomStoryBoardSegue
import UIKit

class TopToBottomSegue: UIStoryboardSegue {
    override func perform() {
        let firstVCView = self.source.view as UIView?
        let secondVCView = self.destination.view as UIView?

        // 画面の大きさを取得
        let screenWidth = UIScreen.main.bounds.size.width
        let screenHeight = UIScreen.main.bounds.size.height

        // 次出てくるviewを最初に今のviewの後ろ側に表示
        secondVCView?.frame = CGRect(x: 0,y: 0,width: screenWidth, height: screenHeight)
        let window = UIApplication.shared.keyWindow
        window?.insertSubview(secondVCView!, at: 0)

        // 邪魔になっている今のviewを画面外まで下げれば終了
        UIView.animate(withDuration: 0.3, animations: { () -> Void in
            firstVCView?.center.y += screenHeight
        }) { (Finished) -> Void in
            self.source.present(self.destination as! UIViewController,
                                                            animated: false,
                                                            completion: nil)
        }

}
}

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away