Compare commits

3 Commits

Author SHA1 Message Date
vegardbm 36157b53f9 remove unnecessary override of viewWillTransition and only load image
only once when view size has changed
2026-07-16 17:50:15 +02:00
vegardbm e94e94f173 fix: set scaling correctly when switching between apps 2026-07-16 17:05:26 +02:00
vegardbm 0f1dc88b87 regex: allow p123-p123 and p123-123 2026-07-15 00:00:48 +02:00
+13 -23
View File
@@ -58,7 +58,6 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
@IBOutlet var scrollingCollectionView: UICollectionView! @IBOutlet var scrollingCollectionView: UICollectionView!
var scrollPos: CGPoint! var scrollPos: CGPoint!
var hasSetContentOffset = false var hasSetContentOffset = false
var pageCount = 0
var imageView = UIImageView() var imageView = UIImageView()
var mode = PageTurnMode.leftToRight var mode = PageTurnMode.leftToRight
@@ -67,8 +66,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
var currentPage: Int! var currentPage: Int!
var progress = ProgressIndices(v: 0, c: 0, i: 0) var progress = ProgressIndices(v: 0, c: 0, i: 0)
var currentPath: URL! var currentPath: URL!
var lastLayoutSize: CGSize = .zero
var changedOrientation = false
var leftTap: UITapGestureRecognizer! var leftTap: UITapGestureRecognizer!
var rightTap: UITapGestureRecognizer! var rightTap: UITapGestureRecognizer!
@@ -673,9 +671,20 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
override func viewDidLayoutSubviews() { override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews() super.viewDidLayoutSubviews()
guard view.bounds.size != lastLayoutSize else { return }
lastLayoutSize = UIScreen.main.bounds.size
if scrollingCollectionView.isHidden == true || mode != .scroll if scrollingCollectionView.isHidden == true || mode != .scroll
|| scrollingCollectionView.contentSize == .zero || scrollingCollectionView.contentSize == .zero
{ {
if metadata == nil { return }
imageLoader.loadImage(
archiveURL: getArchiveURL(progress.v),
filename: getImagePath(progress),
scaling: .scaleAspectFit,
screenSize: UIScreen.main.bounds.size
) { image in
self.imageView.image = image
}
return return
} }
if !hasSetContentOffset, scrollPos != nil { if !hasSetContentOffset, scrollPos != nil {
@@ -686,8 +695,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
} }
scrollingCollectionView.setContentOffset(offset, animated: false) scrollingCollectionView.setContentOffset(offset, animated: false)
hasSetContentOffset = true hasSetContentOffset = true
} else if changedOrientation { } else {
changedOrientation = false
let screenSize = UIScreen.main.bounds.size let screenSize = UIScreen.main.bounds.size
var offset = scrollingCollectionView.contentOffset var offset = scrollingCollectionView.contentOffset
offset.y *= (screenSize.width / screenSize.height) offset.y *= (screenSize.width / screenSize.height)
@@ -1330,24 +1338,6 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
} }
return nil 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 { func getGlobalState() -> GlobalState {