2016-06-18 1 views
1

"Apple Keynote"エフェクトとまったく同じように動作するストーリーボードの2つのシーンの間にセグを構築したいとします(上から下方向)。今私はモーダルセグエと呼ばれるセグを知っていますが、それは下から上の方向に働きます。スウィフトでカスタムセグウェイを設定する(上からボタンの方向)

私を助けてください!

私はどのようなセグアをしたいのかビデオを作りました、それをチェックしてください! https://www.dropbox.com/s/zqyxrm638ellfbx/whatiwant.mov?dl=0

答えて

3

あなたは、このようなカスタムUIStoryboardSegueを実現することができます。

class TopDownSegue: UIStoryboardSegue { 
    let duration: NSTimeInterval = 1 
    let delay: NSTimeInterval = 0 
    let animationOptions: UIViewAnimationOptions = [.CurveEaseInOut] 

    override func perform() { 
     // get views 
     let sourceView = sourceViewController.view 
     let destinationView = destinationViewController.view 

     // get screen height 
     let screenHeight = UIScreen.mainScreen().bounds.size.height 
     destinationView.transform = CGAffineTransformMakeTranslation(0, -screenHeight) 

     // add destination view to view hierarchy 
     UIApplication.sharedApplication().keyWindow?.insertSubview(destinationView, aboveSubview: sourceView) 

     // animate 
     UIView.animateWithDuration(duration, delay: delay, options: animationOptions, animations: { 
      destinationView.transform = CGAffineTransformIdentity 
      }) { (_) in 
       self.sourceViewController.presentViewController(self.destinationViewController, animated: false, completion: nil) 
     } 
    } 
} 

とストーリーボードに新しいカスタムセグエを使用する:

custom segue

+0

はどうもありがとうございました!あなたは私の問題を解決しました!私にそんなに苦労している別の問題を少し助けてくれますか? http://stackoverflow.com/questions/37900927/auto-layout-constrain-confusion –

+0

ページが見つかりません。申し訳ありません。 :)そしてあなたは大歓迎です! –

+0

素晴らしい例です。私がこれを使用すると、ナビゲーションコントローラ "<戻る"がなくなります。これをナビゲーションスタックにどのように追加しますか? –

関連する問題