2016-04-03 7 views
0

私は、現在のビューを左に移動し、同時に次のビューを右から移動するカスタムセグを作成しました。私が最初のseguewayでそれを使用したとき、それは完全に動作しますが、次のseguewayで使用された場合、目的地のビューだけが動きます。セグエのコードは、次のようになります。スウィフトカスタムセグが連続したセグでは機能しません

class CustomSlideSegue: UIStoryboardSegue { 

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

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

     secondVCView.frame = CGRectMake(screenWidth, 0, screenWidth, screenHeight) 

     let window = UIApplication.sharedApplication().keyWindow 
     window?.insertSubview(secondVCView, aboveSubview: firstVCView) 

     UIView.animateWithDuration(0.6, animations: {() -> Void in 
      firstVCView.transform = CGAffineTransformMakeTranslation(-screenWidth, 0) 
      secondVCView.transform = CGAffineTransformMakeTranslation(-screenWidth, 0) 
    }) { (Finished) -> Void in 
      self.sourceViewController.presentViewController(self.destinationViewController as UIViewController, animated: false, completion: nil) 
     } 
    } 
} 

をそしてここで私はセグエ開始どこビューコントローラのボタンアクションメソッドのコードです:ここでは

performSegueWithIdentifier("customSlideSegue", sender: self) 

がseguesを示すビデオです。

The second slide happens after the image picker.

誰もが問題を見ることができますか?または、これをデバッグするにはどうしたらよいですか?返信ありがとう!

+0

実際にカスタムセグを使用するコードをいくつか表示できますか? –

+0

質問に追加しました。私はperformSegueWithIdentifier( "customSlideSegue"、送信者:自己)を使用して、そのボタンが押されたときに呼び出されます。 –

+0

私はもちろん、両方のセグに異なるIDを持っています:) –

答えて

0

問題は、2回目にsegueを呼び出すと、sourceviewcontrollerのビューの変換の値がすでに-screenWidthであるため、画面から押し出されないという問題でした。コードを次のように変更してください:

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

    let screenWidth = UIScreen.mainScreen().bounds.size.width 

    secondVCView.transform = CGAffineTransformMakeTranslation(screenWidth, 0) 

    let window = UIApplication.sharedApplication().keyWindow 
    window?.insertSubview(secondVCView, aboveSubview: firstVCView) 

    UIView.animateWithDuration(0.6, animations: {() -> Void in 
     firstVCView.transform = CGAffineTransformMakeTranslation(-screenWidth, 0) 
     secondVCView.transform = CGAffineTransformIdentity 
    }) { (Finished) -> Void in 
     self.sourceViewController.presentViewController(self.destinationViewController, animated: false, completion: nil) 
    } 
} 
+0

ありがとうたくさん!私はフレームをリセットするときに変換をリセットすると思った!私はiOSのアニメーションやカスタムセグエッテの新機能を利用しています。 –

+0

心配はありません。どういたしまして。 :) –

関連する問題