2020-12-14 03:37:37 +00:00
|
|
|
//
|
|
|
|
// UIWindowSceneDelegate+Close.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 12/12/20.
|
|
|
|
// Copyright © 2020 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
extension UIWindowSceneDelegate {
|
|
|
|
|
|
|
|
func closeWindow(animation: UIWindowScene.DismissalAnimation = .standard, errorHandler: ((Error) -> Void)? = nil) {
|
|
|
|
guard let session = self.window??.windowScene?.session else { return }
|
2021-01-07 00:16:57 +00:00
|
|
|
// Hide the keyboard before dismissing window.
|
|
|
|
// Calling resignFirstResponder() on the window does not work (always returns false).
|
|
|
|
// Using UIApplication.shared.sendAction(#selector(resignFirstResponder), to: nil, from: nil, for: nil)
|
|
|
|
// may not work as desired if the window with focus is not the one being dismissed (in which case it's okay
|
|
|
|
// if the keyboard remains visible).
|
|
|
|
window??.endEditing(true)
|
|
|
|
|
2020-12-14 03:37:37 +00:00
|
|
|
let options = UIWindowSceneDestructionRequestOptions()
|
|
|
|
options.windowDismissalAnimation = animation
|
|
|
|
UIApplication.shared.requestSceneSessionDestruction(session, options: options, errorHandler: errorHandler)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|