2016-07-04 2 views
0

Swiftでスライドアニメーションを作りたいと思います。最初のコントローラーから2番目のコントローラーに移動します。例:POVは最初のVCにあり、ボタンを押すとfirstVCがスライドし、その上に2番目のVC 。それは妥当な移行ですか?もしそうなら、私はこれをどのように達成するでしょうか?ありがとう! ExampleView Swiftでスライドアニメーションを作成する

注:ここでは

は私が探しているものの一例のイメージである私は、私はそれはそれ(または上部)の上に滞在したい、secondViewは最初のビュー上をスライドさせたくありませんの最初のビューは下にスライドします。

+1

これは役立つかもしれません... http://stackoverflow.com/questions/32514836/how-to-add-bottom-swipe-up-view-ios/32516167#32516167 –

+0

多分この記事は次のように役立ちます:http: //stackoverflow.com/a/26569703/3178126それは、カスタムプッシュとポップトランジションを行う方法を教えてくれます。この例ではアルファをアニメーション化しますが、ビューのトランスフォームのプロパティをアニメートすることもできます。 –

答えて

0

このセグを作成するには、UIStoryBoardSegueファイルを作成する必要があります。そのファイルに 、このコードを配置:

override func perform() { 
     var firstVCView = self.sourceViewController.view as UIView! 
     var secondVCView = self.destinationViewController.view as UIView! 

    // Get the screen width and height. 
    let screenWidth = UIScreen.mainScreen().bounds.size.width 
    let screenHeight = UIScreen.mainScreen().bounds.size.height 

    // Specify the initial position of the destination view. 
    secondVCView.frame = CGRectMake(0.0, -screenHeight, screenWidth, screenHeight) 
    firstVCView.frame = CGRectMake(0.0, 0.0, screenWidth, screenHeight) 

    // Access the app's key window and insert the destination view above the current (source) one. 
    let window = UIApplication.sharedApplication().keyWindow 
    window?.insertSubview(secondVCView, aboveSubview: firstVCView) 

    // Animate the transition. 
    UIView.animateWithDuration(0.4, animations: {() -> Void in 

     firstVCView.frame = CGRectOffset(firstVCView.frame, 0.0, screenHeight) 
     secondVCView.frame = CGRectOffset(secondVCView.frame, 0.0, screenHeight) 

    }) { (Finished) -> Void in 
     self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController, 
                 animated: false, 
                 completion: nil) 
    } 
} 

コントロールがセグエを作成します。 「カスタム」を選択します。次に、属性インスペクタでセグファイル名を入力します。あなたのカスタムセグは行きたい!

これが役に立った。

+0

ありがとうございます!私はこれをしばらく理解しようとしてきましたが、これは100%働いていました! – Nickolans

関連する問題