From 330676049092bf96ed601e92966613b9ceaf5f1a Mon Sep 17 00:00:00 2001 From: shoheiyokoyama Date: Thu, 30 Apr 2020 16:07:28 +0900 Subject: [PATCH] Adds condition --- Chausie/PageViewController.swift | 2 +- ChausieTests/Tests/PageViewControllerTests.swift | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Chausie/PageViewController.swift b/Chausie/PageViewController.swift index 09a3e8a..a744466 100644 --- a/Chausie/PageViewController.swift +++ b/Chausie/PageViewController.swift @@ -195,7 +195,7 @@ public final class PageViewController: UIViewController { public override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { super.viewWillTransition(to: size, with: coordinator) - guard scrollView.bounds.width > 0 else { return } + guard viewIfLoaded?.window != nil && scrollView.bounds.width > 0 else { return } isTransitioning = true diff --git a/ChausieTests/Tests/PageViewControllerTests.swift b/ChausieTests/Tests/PageViewControllerTests.swift index af25a44..6577930 100644 --- a/ChausieTests/Tests/PageViewControllerTests.swift +++ b/ChausieTests/Tests/PageViewControllerTests.swift @@ -80,6 +80,8 @@ private final class PageViewControllerTests: XCTestCase { } func testViewFrameAfterRotation() { + let window = UIWindow() + window.addSubview(pageViewController.view) let currentSize = pageViewController.view.bounds.size let newSize = CGSize(width: currentSize.height, height: currentSize.width)