2017-02-04 5 views
0

私はこのコードを左から右に向かっていますが、私はそれを右から左にしたいと思っています。これをどうやってやりますか?あなたがする必要がどのようなどのように私は反対方向にこのセグを作るだろうか?

let screenWidth = (UIScreen.mainScreen().bounds).width 
    let screenHeight = (UIScreen.mainScreen().bounds).height 

    let firstVCView = sourceViewController.view 
    let secondVCView = destinationViewController.view 
    secondVCView.frame = CGRectMake(screenWidth, 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.3, animations: {() -> Void in 
     firstVCView.frame = CGRectOffset(firstVCView.frame, -screenWidth, 0.0) 
     secondVCView.frame = CGRectOffset(secondVCView.frame, -screenWidth, 0.0) 

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

は多分これはあなたを助けることができるhttp://stackoverflow.com/a/35574014/1622430 – carmine

+0

@カルミンMmm。それは、Snapchatのようにスライドする代わりに、View Controllerを前面に置いたように見えるようです。 –

答えて

0

は当初、最初のビューの左ではなく右の2番目のビューを配置しています。

secondVCView.frame = CGRectMake(-screenWidth, 0.0, screenWidth, screenHeight) 

次に、あなたが逆に行きたいアニメーション:

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

だから、最終結果:

let screenWidth = (UIScreen.mainScreen().bounds).width 
let screenHeight = (UIScreen.mainScreen().bounds).height 

let firstVCView = sourceViewController.view 
let secondVCView = destinationViewController.view 
secondVCView.frame = CGRectMake(-screenWidth, 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.3, animations: {() -> Void in 
    firstVCView.frame = CGRectOffset(firstVCView.frame, screenWidth, 0.0) 
    secondVCView.frame = CGRectOffset(secondVCView.frame, screenWidth, 0.0) 

}) { (Finished) -> Void in 
    self.sourceViewController.presentViewController(self.destinationViewController , 
                animated: false, 
                completion: nil) 
} 
関連する問題