From 657ebafde96a2d7cade2082bc1fb30d47ca15cfb Mon Sep 17 00:00:00 2001 From: hyun99999 Date: Wed, 18 Oct 2023 14:11:55 +0900 Subject: [PATCH 1/2] Use UIApplication instead of UIScreen.main on iOS 13.0 and later --- .../VideoCropperViewController.swift | 11 +++++++++-- .../Parents/AssetVideoScrollView.swift | 11 ++++++++++- Sources/PryntTrimmerView/ThumbSelectorView.swift | 12 +++++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/PryntTrimmerViewExample/VideoCropperViewController.swift b/PryntTrimmerViewExample/VideoCropperViewController.swift index 3e2195e..2119c63 100644 --- a/PryntTrimmerViewExample/VideoCropperViewController.swift +++ b/PryntTrimmerViewExample/VideoCropperViewController.swift @@ -51,8 +51,15 @@ class VideoCropperViewController: AssetSelectionViewController { var actualTime = CMTime.zero let image = try? generator.copyCGImage(at: selectedTime, actualTime: &actualTime) if let image = image { - - let selectedImage = UIImage(cgImage: image, scale: UIScreen.main.scale, orientation: .up) + var scale: CGFloat = 0 + + if #available(iOS 13.0, *) { + scale = view.window?.windowScene?.screen.scale ?? .zero + } else { + scale = UIScreen.main.scale + } + + let selectedImage = UIImage(cgImage: image, scale: scale, orientation: .up) let croppedImage = selectedImage.crop(in: videoCropView.getImageCropFrame())! UIImageWriteToSavedPhotosAlbum(croppedImage, nil, nil, nil) } diff --git a/Sources/PryntTrimmerView/Parents/AssetVideoScrollView.swift b/Sources/PryntTrimmerView/Parents/AssetVideoScrollView.swift index 2839f28..7469608 100644 --- a/Sources/PryntTrimmerView/Parents/AssetVideoScrollView.swift +++ b/Sources/PryntTrimmerView/Parents/AssetVideoScrollView.swift @@ -130,7 +130,16 @@ class AssetVideoScrollView: UIScrollView { generator = AVAssetImageGenerator(asset: asset) generator?.appliesPreferredTrackTransform = true - let scaledSize = CGSize(width: maximumSize.width * UIScreen.main.scale, height: maximumSize.height * UIScreen.main.scale) + var scale: CGFloat = 0 + + if #available(iOS 13.0, *) { + let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene + scale = windowScene?.screen.scale ?? .zero + } else { + scale = UIScreen.main.scale + } + + let scaledSize = CGSize(width: maximumSize.width * scale, height: maximumSize.height * scale) generator?.maximumSize = scaledSize var count = 0 diff --git a/Sources/PryntTrimmerView/ThumbSelectorView.swift b/Sources/PryntTrimmerView/ThumbSelectorView.swift index 433b8f5..dc76176 100644 --- a/Sources/PryntTrimmerView/ThumbSelectorView.swift +++ b/Sources/PryntTrimmerView/ThumbSelectorView.swift @@ -132,7 +132,17 @@ public class ThumbSelectorView: AVAssetTimeSelector { let maxDimension = max(assetSize.width, assetSize.height) let minDimension = min(assetSize.width, assetSize.height) let ratio = maxDimension / minDimension - let side = thumbView.frame.height * ratio * UIScreen.main.scale + + var scale: CGFloat = 0 + + if #available(iOS 13.0, *) { + let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene + scale = windowScene?.screen.scale ?? .zero + } else { + scale = UIScreen.main.scale + } + + let side = thumbView.frame.height * ratio * scale return CGSize(width: side, height: side) } From c5118db4bd6ebda9b32e7a9a85f4ad5a30d3f324 Mon Sep 17 00:00:00 2001 From: hyun99999 Date: Thu, 19 Oct 2023 00:44:12 +0900 Subject: [PATCH 2/2] Fix .zero to 1.0 ensure minimal operation through the scale factor. --- PryntTrimmerViewExample/VideoCropperViewController.swift | 2 +- Sources/PryntTrimmerView/Parents/AssetVideoScrollView.swift | 2 +- Sources/PryntTrimmerView/ThumbSelectorView.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/PryntTrimmerViewExample/VideoCropperViewController.swift b/PryntTrimmerViewExample/VideoCropperViewController.swift index 2119c63..ae38959 100644 --- a/PryntTrimmerViewExample/VideoCropperViewController.swift +++ b/PryntTrimmerViewExample/VideoCropperViewController.swift @@ -54,7 +54,7 @@ class VideoCropperViewController: AssetSelectionViewController { var scale: CGFloat = 0 if #available(iOS 13.0, *) { - scale = view.window?.windowScene?.screen.scale ?? .zero + scale = view.window?.windowScene?.screen.scale ?? 1.0 } else { scale = UIScreen.main.scale } diff --git a/Sources/PryntTrimmerView/Parents/AssetVideoScrollView.swift b/Sources/PryntTrimmerView/Parents/AssetVideoScrollView.swift index 7469608..67c2a72 100644 --- a/Sources/PryntTrimmerView/Parents/AssetVideoScrollView.swift +++ b/Sources/PryntTrimmerView/Parents/AssetVideoScrollView.swift @@ -134,7 +134,7 @@ class AssetVideoScrollView: UIScrollView { if #available(iOS 13.0, *) { let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene - scale = windowScene?.screen.scale ?? .zero + scale = windowScene?.screen.scale ?? 1.0 } else { scale = UIScreen.main.scale } diff --git a/Sources/PryntTrimmerView/ThumbSelectorView.swift b/Sources/PryntTrimmerView/ThumbSelectorView.swift index dc76176..7d7cf94 100644 --- a/Sources/PryntTrimmerView/ThumbSelectorView.swift +++ b/Sources/PryntTrimmerView/ThumbSelectorView.swift @@ -137,7 +137,7 @@ public class ThumbSelectorView: AVAssetTimeSelector { if #available(iOS 13.0, *) { let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene - scale = windowScene?.screen.scale ?? .zero + scale = windowScene?.screen.scale ?? 1.0 } else { scale = UIScreen.main.scale }