remove unnecessary override of viewWillTransition and only load image
only once when view size has changed
This commit is contained in:
@@ -58,7 +58,6 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
@IBOutlet var scrollingCollectionView: UICollectionView!
|
||||
var scrollPos: CGPoint!
|
||||
var hasSetContentOffset = false
|
||||
var pageCount = 0
|
||||
|
||||
var imageView = UIImageView()
|
||||
var mode = PageTurnMode.leftToRight
|
||||
@@ -67,8 +66,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
var currentPage: Int!
|
||||
var progress = ProgressIndices(v: 0, c: 0, i: 0)
|
||||
var currentPath: URL!
|
||||
|
||||
var changedOrientation = false
|
||||
var lastLayoutSize: CGSize = .zero
|
||||
|
||||
var leftTap: UITapGestureRecognizer!
|
||||
var rightTap: UITapGestureRecognizer!
|
||||
@@ -673,6 +671,8 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
|
||||
override func viewDidLayoutSubviews() {
|
||||
super.viewDidLayoutSubviews()
|
||||
guard view.bounds.size != lastLayoutSize else { return }
|
||||
lastLayoutSize = UIScreen.main.bounds.size
|
||||
if scrollingCollectionView.isHidden == true || mode != .scroll
|
||||
|| scrollingCollectionView.contentSize == .zero
|
||||
{
|
||||
@@ -695,8 +695,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
}
|
||||
scrollingCollectionView.setContentOffset(offset, animated: false)
|
||||
hasSetContentOffset = true
|
||||
} else if changedOrientation {
|
||||
changedOrientation = false
|
||||
} else {
|
||||
let screenSize = UIScreen.main.bounds.size
|
||||
var offset = scrollingCollectionView.contentOffset
|
||||
offset.y *= (screenSize.width / screenSize.height)
|
||||
@@ -1339,24 +1338,6 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
override func viewWillTransition(
|
||||
to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator
|
||||
) {
|
||||
super.viewWillTransition(to: size, with: coordinator)
|
||||
if mode != .scroll {
|
||||
imageLoader.loadImage(
|
||||
archiveURL: getArchiveURL(progress.v),
|
||||
filename: getImagePath(progress),
|
||||
scaling: .scaleAspectFit,
|
||||
screenSize: size
|
||||
) { image in
|
||||
self.imageView.image = image
|
||||
}
|
||||
} else {
|
||||
changedOrientation = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getGlobalState() -> GlobalState {
|
||||
|
||||
Reference in New Issue
Block a user