Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // UIViewController+CustomAnimations.swift
- // NavBarCustomOrientationDemo
- //
- // Created by Aleksandar Geyman on 11.03.20.
- // Copyright © 2020 Aleksandar Geyman. All rights reserved.
- //
- import UIKit
- private struct AnimationConstants {
- static let duration = 0.25
- }
- private enum AnimationType {
- case present
- case dismiss
- }
- extension UIViewController {
- func presentWithCustomAnimation(viewControllerToPresent: UIViewController, completion: (() -> Void)?) {
- view.window?.layer.add(configureAnimation(for: .present), forKey: kCATransition)
- present(viewControllerToPresent, animated: false, completion: completion)
- }
- func dismissWithCustomAnimation(completion: (() -> Void)?) {
- view.window?.layer.add(configureAnimation(for: .dismiss), forKey: kCATransition)
- dismiss(animated: false, completion: completion)
- }
- private func configureAnimation(for animationType: AnimationType) -> CATransition {
- var type: CATransitionType
- var subType: CATransitionSubtype
- switch animationType {
- case .present:
- type = .push
- subType = .fromRight
- case .dismiss:
- type = .push
- subType = .fromLeft
- }
- let transition = CATransition()
- transition.duration = AnimationConstants.duration
- transition.type = type
- transition.subtype = subType
- return transition
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement