自定義segue的方向

花了挺久時間,終於通過google在stake overflow上找到了解決方式。


總結一下:重寫一個custom的segue,在storyboard的右邊設置segue爲custom,並設置其對應的class。


創建一個segue的類,繼承UIStoryboardSegue,代碼如下:


import UIKit


class SegueFromTop: UIStoryboardSegue {

    

    

    override func perform()

    {

        let src = self.source

        let dst = self.destination

        

        src.view.superview?.insertSubview(dst.view, aboveSubview: src.view)

        dst.view.transform = CGAffineTransform(translationX: 0, y: -src.view.frame.size.height)

        

        UIView.animate(withDuration: 0.25,

                                   delay: 0.0,

                                   options: UIViewAnimationOptions.curveEaseInOut,

                                   animations: {

                                    dst.view.transform = CGAffineTransform(translationX: 0, y: 0)

        },

                                   completion: { finished in

                                    src.present(dst, animated: false, completion: nil)

        }

        )

    }

}


親測可用!!!!!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章