自定义segue的方向

来源:互联网 发布:数据分析合同 编辑:程序博客网 时间:2024/05/19 18:11

花了挺久时间,终于通过google在stake overflow上找到了解决方式。


总结一下:重写一个custom的segue,在storyboard的右边设置segue为custom,并设置其对应的class。


创建一个segue的类,继承UIStoryboardSegue,代码如下:


import UIKit


class SegueFromTop: UIStoryboardSegue {

    

    

    overridefunc 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)

        }

        )

    }

}


亲测可用!!!!!
原创粉丝点击