fix: scrolling set offset on startup, scale fill to width, info update, background color
This commit is contained in:
@@ -124,6 +124,20 @@ final class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
if let alert = pendingAlert {
|
||||
present(alert, animated: false, completion: nil)
|
||||
}
|
||||
if !hasSetContentOffset, scrollPos != nil {
|
||||
let screenSize = UIScreen.main.bounds.size
|
||||
var offset = scrollPos!
|
||||
if screenSize.width > screenSize.height {
|
||||
offset.y *= (screenSize.width / screenSize.height)
|
||||
}
|
||||
scrollingCollectionView.setContentOffset(offset, animated: false)
|
||||
hasSetContentOffset = true
|
||||
} else {
|
||||
let screenSize = UIScreen.main.bounds.size
|
||||
var offset = scrollingCollectionView.contentOffset
|
||||
offset.y *= (screenSize.width / screenSize.height)
|
||||
scrollingCollectionView.setContentOffset(offset, animated: false)
|
||||
}
|
||||
}
|
||||
|
||||
func setup() {
|
||||
@@ -872,8 +886,8 @@ final class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
func scrollViewDidScroll(_: UIScrollView) {
|
||||
if scrollingCollectionView.isHidden { return }
|
||||
let centerPoint = CGPoint(
|
||||
x: scrollingCollectionView.bounds.midX + scrollingCollectionView.contentOffset.x,
|
||||
y: scrollingCollectionView.bounds.midY + scrollingCollectionView.contentOffset.y
|
||||
x: scrollingCollectionView.bounds.midX,
|
||||
y: scrollingCollectionView.bounds.midY,
|
||||
)
|
||||
|
||||
if let indexPath = scrollingCollectionView.indexPathForItem(at: centerPoint) {
|
||||
@@ -907,20 +921,6 @@ final class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
}
|
||||
return
|
||||
}
|
||||
if !hasSetContentOffset, scrollPos != nil {
|
||||
let screenSize = UIScreen.main.bounds.size
|
||||
var offset = scrollPos!
|
||||
if screenSize.width > screenSize.height {
|
||||
offset.y *= (screenSize.width / screenSize.height)
|
||||
}
|
||||
scrollingCollectionView.setContentOffset(offset, animated: false)
|
||||
hasSetContentOffset = true
|
||||
} else {
|
||||
let screenSize = UIScreen.main.bounds.size
|
||||
var offset = scrollingCollectionView.contentOffset
|
||||
offset.y *= (screenSize.width / screenSize.height)
|
||||
scrollingCollectionView.setContentOffset(offset, animated: false)
|
||||
}
|
||||
}
|
||||
|
||||
func readComic(name: String) {
|
||||
@@ -941,6 +941,7 @@ final class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
imageView.isHidden = mode == .scroll
|
||||
if mode == .scroll {
|
||||
scrollingCollectionView.reloadData()
|
||||
updateInfo()
|
||||
} else {
|
||||
setImages()
|
||||
}
|
||||
@@ -959,7 +960,7 @@ final class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
scrollingCollectionView.translatesAutoresizingMaskIntoConstraints = false
|
||||
scrollingCollectionView.dataSource = self
|
||||
scrollingCollectionView.delegate = self
|
||||
scrollingCollectionView.backgroundColor = .white
|
||||
scrollingCollectionView.backgroundColor = .clear
|
||||
scrollingCollectionView.isHidden = true
|
||||
scrollingCollectionView.register(
|
||||
ScrollingImageCell.self, forCellWithReuseIdentifier: "ScrollingImageCell"
|
||||
@@ -1687,6 +1688,7 @@ enum Rotation {
|
||||
}
|
||||
|
||||
class ImageLoader {
|
||||
// Fill is kind of a lie here, it is actually FillToWidth, because that is what makes sense for scrolling.
|
||||
private let cache = NSCache<NSString, UIImage>()
|
||||
private let portraitFitCache = NSCache<NSString, UIImage>()
|
||||
private let landscapeFitCache = NSCache<NSString, UIImage>()
|
||||
@@ -1836,7 +1838,9 @@ class ImageLoader {
|
||||
height: min(screenSize.height, screenSize.width)
|
||||
)
|
||||
}
|
||||
let scaledSize = aspectSize(for: image.size, in: resizeTo, scaling: scaling)
|
||||
let scaledSize = image.size.height > image.size.width && scaling == .scaleAspectFill ?
|
||||
aspectSize(for: image.size, in: resizeTo, scaling: scaling) :
|
||||
aspectSize(for: image.size, in: resizeTo, scaling: .scaleAspectFit)
|
||||
let scaledImage = resizeImage(image, to: scaledSize)
|
||||
let cost = imageByteSize(scaledImage)!
|
||||
switch (orientation, scaling) {
|
||||
@@ -2235,28 +2239,29 @@ extension ViewController {
|
||||
|
||||
private func makePageTurnTree() -> [SettingsMenuItem] {
|
||||
return pageTurnDefaultItems { [self] pageTurnMode in
|
||||
if self.mode == pageTurnMode { return }
|
||||
|
||||
if self.mode != .scroll {
|
||||
let archiveURL = getArchiveURL(progress.v)
|
||||
imageLoader.loadImage(
|
||||
archiveURL: archiveURL,
|
||||
filename: getImagePath(self.progress),
|
||||
scaling: .scaleAspectFit,
|
||||
screenSize: UIScreen.main.bounds.size
|
||||
) { [weak self] image in
|
||||
self?.imageView.image = image
|
||||
}
|
||||
if mode == pageTurnMode { return }
|
||||
let scrollSwitch = mode != .scroll && pageTurnMode != .scroll
|
||||
mode = pageTurnMode
|
||||
saveLocalState()
|
||||
if scrollSwitch { return }
|
||||
let archiveURL = getArchiveURL(progress.v)
|
||||
imageLoader.loadImage(
|
||||
archiveURL: archiveURL,
|
||||
filename: getImagePath(progress),
|
||||
scaling: .scaleAspectFit,
|
||||
screenSize: UIScreen.main.bounds.size
|
||||
) { [weak self] image in
|
||||
self?.imageView.image = image
|
||||
}
|
||||
|
||||
scrollingCollectionView.isHidden = mode != .scroll
|
||||
leftView.isHidden = mode == .scroll
|
||||
rightView.isHidden = mode == .scroll
|
||||
imageView.isHidden = mode == .scroll
|
||||
|
||||
if mode == .scroll {
|
||||
scrollingCollectionView.reloadData()
|
||||
}
|
||||
self.mode = pageTurnMode
|
||||
saveLocalState()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user