fix loading scaled image on viewTransition
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
// TODO: Properly avoid swallowing of input from UICollectionView used for scrolling
|
||||
// TODO: Convert between state for normal and scrolling page turn
|
||||
// TODO: Support reading with scrolling and landscape mode
|
||||
// FIXME: Update comicCollectionView when switching between landscape and portrait mode
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
@@ -102,7 +101,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
|
||||
var imageView = UIImageView()
|
||||
var mode = PageTurnMode.leftToRight
|
||||
var metadataList: [String: Metadata] = [:]
|
||||
var metadataList: [URL: Metadata] = [:]
|
||||
var metadata: Metadata!
|
||||
var currentPage: Int!
|
||||
var progress = ProgressIndices(v: 0, c: 0, i: 0)
|
||||
@@ -931,7 +930,8 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
} else {
|
||||
imageLoader.loadImage(
|
||||
at: getImagePath(progress: progress),
|
||||
scaling: .scaleAspectFit
|
||||
scaling: .scaleAspectFit,
|
||||
screenSize: UIScreen.main.bounds.size
|
||||
) { [weak self] image in
|
||||
self?.imageView.image = image
|
||||
}
|
||||
@@ -1068,7 +1068,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
}
|
||||
progress = newProgress
|
||||
if let path = getImagePath(progress: progress) {
|
||||
imageLoader.loadImage(at: path, scaling: scaling) { [weak self] image in
|
||||
imageLoader.loadImage(at: path, scaling: scaling, screenSize: UIScreen.main.bounds.size) { [weak self] image in
|
||||
self?.imageView.image = image
|
||||
self?.updateInfo()
|
||||
}
|
||||
@@ -1079,7 +1079,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
for _ in 0 ... preloadCount {
|
||||
newProgress = getProgressIndicesFromTurn(turn: .next, progress: newProgress)
|
||||
if let path = getImagePath(progress: newProgress) {
|
||||
imageLoader.preloadImage(at: path, scaling: scaling)
|
||||
imageLoader.preloadImage(at: path, scaling: scaling, screenSize: UIScreen.main.bounds.size)
|
||||
} else {
|
||||
print("could not preload image")
|
||||
}
|
||||
@@ -1222,7 +1222,8 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
imageLoader.loadImage(
|
||||
at:
|
||||
getImagePath(progress: progress),
|
||||
scaling: scaling
|
||||
scaling: scaling,
|
||||
screenSize: UIScreen.main.bounds.size
|
||||
) { [weak self] image in
|
||||
self?.imageView.image = image
|
||||
self?.updateInfo()
|
||||
@@ -1231,7 +1232,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
var newProgress = progress
|
||||
for _ in 0 ... preloadCount {
|
||||
newProgress = getProgressIndicesFromTurn(turn: .next, progress: newProgress)
|
||||
imageLoader.preloadImage(at: getImagePath(progress: newProgress), scaling: scaling)
|
||||
imageLoader.preloadImage(at: getImagePath(progress: newProgress), scaling: scaling, screenSize: UIScreen.main.bounds.size)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1251,7 +1252,8 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
if mode != .scroll {
|
||||
imageLoader.loadImage(
|
||||
at: getImagePath(progress: progress),
|
||||
scaling: .scaleAspectFit
|
||||
scaling: .scaleAspectFit,
|
||||
screenSize: size
|
||||
) { image in
|
||||
self.imageView.image = image
|
||||
}
|
||||
@@ -1436,15 +1438,15 @@ class ImageLoader {
|
||||
cache.totalCostLimit = 128 * 1024 * 1024
|
||||
}
|
||||
|
||||
func preloadImage(at path: URL, scaling: UIView.ContentMode) {
|
||||
loadImage(at: path, scaling: scaling, completion: nil)
|
||||
func preloadImage(at path: URL, scaling: UIView.ContentMode, screenSize: CGSize) {
|
||||
loadImage(at: path, scaling: scaling, screenSize: screenSize, completion: nil)
|
||||
}
|
||||
|
||||
func loadImage(
|
||||
at path: URL, scaling: UIView.ContentMode,
|
||||
screenSize: CGSize,
|
||||
completion: ((UIImage?) -> Void)?
|
||||
) {
|
||||
let screenSize = UIScreen.main.bounds.size
|
||||
let rotation: Rotation!
|
||||
if screenSize.width > screenSize.height {
|
||||
rotation = Rotation.horizontal
|
||||
|
||||
Reference in New Issue
Block a user