Reputation: 366
When my custom segue's animation is being performed, destination view appears black. After animation ends, view appears and looks good.
Here are the screenshots:
Animation scene:
View after segue/animation finished:
Here is the custom segue class:
class SegueToPreview: 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, screenHeight, 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.2, 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 as! UIViewController,
animated: false,
completion: nil)
}
}
While unwind segue works just fine, showing both views.
I suppose that the view is not loaded while the animation is being performed, but have no idea how to fix that.
Upvotes: 0
Views: 104
Reputation: 104082
Your initial position for the destination vc's view is setup incorrectly (assuming that you want the view to move in from the right); you have it positioned below the screen, instead of to the right of the screen,
secondVCView.frame = CGRectMake(0.0, screenHeight, screenWidth, screenHeight)
This should be,
secondVCView.frame = CGRectMake(screenWidth, 0, screenWidth, screenHeight)
Upvotes: 2