2015-07-13 62 views
0

我一直在關注如何實現自定義塞格的教程。使用滑動手勢 - 我滑動手指的賽格作品,但不是一個平滑的過渡,其中第二個ViewController向上/向下滑動以取代當前的,我得到一個黑色屏幕,然後目標ViewController加載..塞格動畫黑屏/毛刺&延長滑動手勢長度

發生這種情況在前進和倒帶時段。

我附加了我正常的賽格動畫代碼(不倒帶)。

另外,當我輕輕滑動屏幕時,segue瞬間發生。我會如何做到這一點,所以直到我的手指被擡起(或在模擬器的情況下,鼠標點擊),纔會發生延續。我需要使用scrollViews嗎?或者這種效果可能只是使用swipeGestureRecognizers &自定義segues。

謝謝!

class FirstCustomSegue: UIStoryboardSegue { 

override func perform() { 

    // 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 

      // 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) 
      } 
     } 
    } 

} 

回答

1

試試這個代碼,我改變了對self.destinationViewController...

class FirstCustomSegue: UIStoryboardSegue { 

    override func perform() { 

     // 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 

       // 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.storyboard.instantiateViewControllerWithIdentifier("YOUR_IDENTIFIER"), 
          animated: false, 
          completion: nil) 
       } 
     } 
    } 

} 

最後一行與您的視圖控制器相匹配的故事板ID替換YOUR_IDENTIFIER

+0

太棒了! - 非常感謝 - 我剛剛刪除了最後一個動畫塊。你知道如何用swipeGestureRecognizer解決這個問題嗎?一旦我做了最小的滑動,就會發生segue ..是否有可能沒有segue開始,直到我開始或我需要使用scrollView才能獲得所需的效果? – simlimsd3