Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
3
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

@nasutaro211

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

概要

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
3
Help us understand the problem. What are the problem?