Skip to content

Commit

Permalink
bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Koji Murata committed Jul 26, 2017
1 parent f380c8b commit d036f3b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
37 changes: 22 additions & 15 deletions PictureInPicture/Classes/PictureInPictureWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,25 @@ final class PictureInPictureWindow: UIWindow {
private let userInterfaceShutoutView = UIView()

func present(with viewController: UIViewController, makeLargerIfNeeded: Bool) {
rootViewController = viewController

if beforePresenting {
beforePresenting = false
bounds = UIScreen.main.bounds
frame.origin.y = UIScreen.main.bounds.height
UIView.animate(withDuration: animationDuration, delay: 0, options: .curveEaseOut, animations: {
self.frame.origin.y = 0
}, completion: nil)
makeKeyAndVisible()
} else if makeLargerIfNeeded {
applyLarge()
let handler = {
self.rootViewController = viewController

if self.beforePresenting {
self.beforePresenting = false
self.bounds = UIScreen.main.bounds
self.frame.origin.y = UIScreen.main.bounds.height
UIView.animate(withDuration: self.animationDuration, delay: 0, options: .curveEaseOut, animations: {
self.frame.origin.y = 0
}, completion: nil)
self.makeKeyAndVisible()
} else if makeLargerIfNeeded {
self.applyLarge()
}
}
if let rootViewController = rootViewController {
rootViewController.dismissPresentedViewControllers(completion: handler)
} else {
handler()
}
}

Expand All @@ -36,7 +43,7 @@ final class PictureInPictureWindow: UIWindow {
UIView.animate(withDuration: animationDuration, animations: {
self.frame.origin.y = UIScreen.main.bounds.height
}, completion: { _ in
self.rootViewController?.dismissWithPresentedViewController {
self.rootViewController?.dismissPresentedViewControllers {
self.disposeHandler()
NotificationCenter.default.post(name: .PictureInPictureDismissed, object: nil)
}
Expand All @@ -45,14 +52,14 @@ final class PictureInPictureWindow: UIWindow {
UIView.animate(withDuration: animationDuration, animations: {
self.alpha = 0
}, completion: { _ in
self.rootViewController?.dismissWithPresentedViewController {
self.rootViewController?.dismissPresentedViewControllers {
self.disposeHandler()
NotificationCenter.default.post(name: .PictureInPictureDismissed, object: nil)
}
})
}
} else {
self.rootViewController?.dismissWithPresentedViewController {
self.rootViewController?.dismissPresentedViewControllers {
self.disposeHandler()
NotificationCenter.default.post(name: .PictureInPictureDismissed, object: nil)
}
Expand Down
10 changes: 9 additions & 1 deletion PictureInPicture/Classes/UIViewController+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ extension UIViewController {
view.setNeedsUpdateConstraints()
}

func dismissWithPresentedViewController(completion: @escaping () -> Void) {
func dismissPresentedViewControllers(completion: @escaping () -> Void) {
if let vc = presentedViewController {
vc.dismissWithPresentedViewController(completion: completion)
} else {
completion()
}
}

private func dismissWithPresentedViewController(completion: @escaping () -> Void) {
if let vc = presentedViewController {
vc.dismissWithPresentedViewController {
self.dismiss(animated: false, completion: completion)
Expand Down

0 comments on commit d036f3b

Please sign in to comment.