Created
September 3, 2017 21:25
-
-
Save eivindml/4c1c3f5cd3309a97afc528318d16547f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ModalSegue.swift | |
// HabitTracker | |
// | |
// Created by Eivind Lindbråten on 03.09.2017. | |
// Copyright © 2017 Eivind Lindbråten. All rights reserved. | |
// | |
import UIKit | |
class ModalSegue: UIStoryboardSegue { | |
override func perform() { | |
// Assign the source and destination views to local variables. | |
let firstVCView = self.source.view as UIView! | |
let secondVCView = self.destination.view as UIView! | |
// Get the screen width and height. | |
let screenWidth = UIScreen.main.bounds.size.width | |
let screenHeight = UIScreen.main.bounds.size.height | |
// Specify the initial position of the destination view. | |
secondVCView?.frame = CGRect(x: 0.0, y: screenHeight, width: screenWidth, height: screenHeight) | |
// Access the app's key window and insert the destination view above the current (source) one. | |
let window = UIApplication.shared.keyWindow | |
window?.insertSubview(secondVCView!, aboveSubview: firstVCView!) | |
// Animate the transition. | |
UIView.animate(withDuration: 0.4, animations: { () -> Void in | |
//firstVCView?.frame = (firstVCView?.frame.offsetBy(dx: 0.0, dy: -screenHeight))! | |
secondVCView?.frame = (secondVCView?.frame.offsetBy(dx: 20.0, dy: -screenHeight + 40.0))! | |
// TODO: Let it keep this size?! | |
let rect = CGSize(width: screenWidth - 40.0, height: screenHeight - 40.0) | |
secondVCView?.frame.size = rect | |
secondVCView?.layer.shadowColor = UIColor.black.cgColor | |
secondVCView?.layer.shadowOpacity = 0.5 | |
secondVCView?.layer.shadowRadius = 8.0 | |
secondVCView?.layer.shadowOffset = CGSize(width: 0, height: 3) | |
secondVCView?.clipsToBounds = false | |
}) { (Finished) -> Void in | |
self.source.present(self.destination as UIViewController, animated: false, completion: nil) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Something like this: