2015-08-04 3 views
1

У меня есть следующий быстрый код, и то, что я пытаюсь достичь, это segue, который скользит сверху. Я хочу, чтобы secondVCView был ниже первогоVCView, и для первогоVCView можно было отключить отображение второгоVCView.UIStoryboardSegue: вид сверху не сползает

В настоящее время нет анимации, и она просто мигает во второмVCView.

Большое спасибо

import UIKit 

class TopToBottomSegue: UIStoryboardSegue { 

override func perform() { 

    // Assign the source and destination views to local variables. 
    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, screenWidth, screenHeight) 

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

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

     firstVCView.frame = CGRectOffset(firstVCView.frame, 0.0, screenHeight) 
     //secondVCView.frame = CGRectOffset(secondVCView.frame, -screenWidth, 0.0) 

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

    } 
} 

ответ

0

Я не уверен, что это правильный способ сделать это, но я сумел заставить его работать, вставляя обе точки зрения.

L

-

import UIKit 

class TopToBottomSegue: UIStoryboardSegue { 

override func perform() { 
    // Assign the source and destination views to local variables. 
    let firstVCView = self.sourceViewController.view as UIView! 
    let secondVCView = self.destinationViewController.view as UIView! 

    // Get the screen width, height and status bar height. 
    let screenWidth = UIScreen.mainScreen().bounds.size.width 
    let screenHeight = UIScreen.mainScreen().bounds.size.height 
    let statusBarHeight = self.statusBarHeight() 

    // Specify the initial position of both views. 
    secondVCView.frame = CGRectMake(0.0, 0.0, screenWidth, screenHeight) 
    firstVCView.frame = CGRectMake(0.0, statusBarHeight, screenWidth, screenHeight) 

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

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

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

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

} 
func statusBarHeight() -> CGFloat { 
    let statusBarSize = UIApplication.sharedApplication().statusBarFrame.size 
    return Swift.min(statusBarSize.width, statusBarSize.height) 
} 
} 
1

Насколько я знаю, вам нужно позвонить layoutIfNeed в animateWithduration блок для того, чтобы получить плавную анимацию.

Привет

Смежные вопросы