diff --git a/NKModalPresenter.podspec b/NKModalPresenter.podspec index 8edbe17..db0cfdc 100644 --- a/NKModalPresenter.podspec +++ b/NKModalPresenter.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'NKModalPresenter' - s.version = '1.6.3' + s.version = '1.6.4' s.summary = 'Present UIViewController modally' s.description = <<-DESC Present UIViewController modally easily and beautifully with animation. diff --git a/NKModalPresenter/NKModalController.swift b/NKModalPresenter/NKModalController.swift index 51619a1..77bc365 100644 --- a/NKModalPresenter/NKModalController.swift +++ b/NKModalPresenter/NKModalController.swift @@ -92,7 +92,7 @@ public extension NKModalControllerDelegate { func backgroundColor(modalController: NKModalController) -> UIColor { return NKModalController.backgroundColor } func cornerRadius(modalController: NKModalController) -> CGFloat { return NKModalController.cornerRadius } func cornerMask(modalController: NKModalController) -> CACornerMask { return [.layerMaxXMaxYCorner, .layerMaxXMinYCorner, .layerMinXMaxYCorner, .layerMinXMinYCorner] } - func windowLevel(modalController: NKModalController) -> UIWindow.Level { return .normal } + func windowLevel(modalController: NKModalController) -> UIWindow.Level { return .normal + 1 } func transitionView(modalController: NKModalController) -> UIView? { return nil } } @@ -255,7 +255,7 @@ public class NKModalController: NKModalContainerViewController { let containerView = UIView() var window: UIWindow? - var lastWindow: UIWindow? + weak var lastWindow: UIWindow? var lastPosition: (container: UIView, frame: CGRect)? var anchorCapturedView: UIImageView? var contentCapturedView: UIImageView? @@ -622,24 +622,28 @@ public class NKModalController: NKModalContainerViewController { self.isAnimating = false self.isDismissing = false - if NKModalPresenter.shared.activeModalControllers.isEmpty { - self.lastWindow?.makeKeyAndVisible() - } - else { - self.lastWindow = nil - } - self.window?.rootViewController?.resignFirstResponder() self.window?.rootViewController = nil self.window?.removeFromSuperview() self.window = nil + if NKModalPresenter.shared.activeModalControllers.isEmpty || NKModalPresenter.shared.topModalController == self { + self.lastWindow?.makeKeyAndVisible() + } + + self.lastWindow = nil + self.didDismiss?(self) self.delegate?.modalController(self, didDismiss: self.contentViewController) NotificationCenter.default.post(name: NKModalController.didDismiss, object: self, userInfo: nil) self.contentView = nil self.contentViewController = nil + + if UIWindow.keyWindow == nil { + UIApplication.shared.windows.last?.makeKeyAndVisible() + } + completion?() } }