diff --git a/Source/Configuration/YPImagePickerConfiguration.swift b/Source/Configuration/YPImagePickerConfiguration.swift index af6f6d4e5..693a2956a 100644 --- a/Source/Configuration/YPImagePickerConfiguration.swift +++ b/Source/Configuration/YPImagePickerConfiguration.swift @@ -20,7 +20,15 @@ public struct YPImagePickerConfiguration { public static var widthOniPad: CGFloat = -1 public static var screenWidth: CGFloat { - var screenWidth: CGFloat = UIScreen.main.bounds.width + var screenWidth: CGFloat = 0 + + if #available(iOS 13.0, *) { + let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene + screenWidth = windowScene?.screen.bounds.width ?? 1.0 + } else { + screenWidth = UIScreen.main.bounds.width + } + if UIDevice.current.userInterfaceIdiom == .pad && YPImagePickerConfiguration.widthOniPad > 0 { screenWidth = YPImagePickerConfiguration.widthOniPad } diff --git a/Source/Filters/Photo/YPFiltersView.swift b/Source/Filters/Photo/YPFiltersView.swift index da1337c7c..d9b6c7aca 100644 --- a/Source/Filters/Photo/YPFiltersView.swift +++ b/Source/Filters/Photo/YPFiltersView.swift @@ -32,7 +32,15 @@ class YPFiltersView: UIView { ) ) - let isIphone4 = UIScreen.main.bounds.height == 480 + var height: CGFloat = 0 + + if #available(iOS 13.0, *) { + height = window?.windowScene?.screen.bounds.height ?? .zero + } else { + height = UIScreen.main.bounds.height + } + + let isIphone4 = height == 480 let sideMargin: CGFloat = isIphone4 ? 20 : 0 |-sideMargin-imageView.top(0)-sideMargin-| diff --git a/Source/Filters/Photo/YPPhotoFiltersVC.swift b/Source/Filters/Photo/YPPhotoFiltersVC.swift index e8917121c..c82a4918f 100644 --- a/Source/Filters/Photo/YPPhotoFiltersVC.swift +++ b/Source/Filters/Photo/YPPhotoFiltersVC.swift @@ -126,7 +126,15 @@ open class YPPhotoFiltersVC: UIViewController, IsMediaFilterVC, UIGestureRecogni fileprivate func thumbFromImage(_ img: UIImage) -> CIImage { let k = img.size.width / img.size.height - let scale = UIScreen.main.scale + + var scale: CGFloat = 0 + + if #available(iOS 13.0, *) { + scale = window?.windowScene?.screen.scale ?? 1.0 + } else { + scale = UIScreen.main.scale + } + let thumbnailHeight: CGFloat = 300 * scale let thumbnailWidth = thumbnailHeight * k let thumbnailSize = CGSize(width: thumbnailWidth, height: thumbnailHeight) diff --git a/Source/Pages/Gallery/Album/YPAlbumsManager.swift b/Source/Pages/Gallery/Album/YPAlbumsManager.swift index aa6b74c7c..4163641e2 100644 --- a/Source/Pages/Gallery/Album/YPAlbumsManager.swift +++ b/Source/Pages/Gallery/Album/YPAlbumsManager.swift @@ -36,7 +36,15 @@ class YPAlbumsManager { if album.numberOfItems > 0 { let r = PHAsset.fetchKeyAssets(in: assetCollection, options: nil) if let first = r?.firstObject { - let deviceScale = UIScreen.main.scale + var deviceScale: CGFloat = 0 + + if #available(iOS 13.0, *) { + let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene + deviceScale = windowScene?.screen.scale ?? 1.0 + } else { + deviceScale = UIScreen.main.scale + } + let targetSize = CGSize(width: 78*deviceScale, height: 78*deviceScale) let options = PHImageRequestOptions() options.isSynchronous = true diff --git a/Source/Pages/Gallery/LibraryMediaManager.swift b/Source/Pages/Gallery/LibraryMediaManager.swift index 9b10a56ea..57791c9dc 100644 --- a/Source/Pages/Gallery/LibraryMediaManager.swift +++ b/Source/Pages/Gallery/LibraryMediaManager.swift @@ -40,7 +40,17 @@ class LibraryMediaManager { func updateCachedAssets(in collectionView: UICollectionView) { let screenWidth = YPImagePickerConfiguration.screenWidth - let size = screenWidth / 4 * UIScreen.main.scale + + var scale: CGFloat = 0 + + if #available(iOS 13.0, *) { + let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene + scale = windowScene?.screen.scale ?? 1.0 + } else { + scale = UIScreen.main.scale + } + + let size = screenWidth / 4 * scale let cellSize = CGSize(width: size, height: size) var preheatRect = collectionView.bounds diff --git a/Source/Pages/Gallery/YPLibraryView.swift b/Source/Pages/Gallery/YPLibraryView.swift index d42db8866..09f39e147 100644 --- a/Source/Pages/Gallery/YPLibraryView.swift +++ b/Source/Pages/Gallery/YPLibraryView.swift @@ -156,11 +156,21 @@ internal final class YPLibraryView: UIView { } func cellSize() -> CGSize { - var screenWidth: CGFloat = UIScreen.main.bounds.width + var screenWidth: CGFloat = 0 + var scale: CGFloat = 0 + + if #available(iOS 13.0, *) { + screenWidth = window?.windowScene?.screen.bounds.width ?? 1.0 + scale = window?.windowScene?.screen.scale ?? 1.0 + } else { + screenWidth = UIScreen.main.bounds.width + scale = UIScreen.main.scale + } + if UIDevice.current.userInterfaceIdiom == .pad && YPImagePickerConfiguration.widthOniPad > 0 { screenWidth = YPImagePickerConfiguration.widthOniPad } - let size = screenWidth / 4 * UIScreen.main.scale + let size = screenWidth / 4 * scale return CGSize(width: size, height: size) } diff --git a/Source/Pages/Photo/YPCameraView.swift b/Source/Pages/Photo/YPCameraView.swift index 451e7240f..01cd1c528 100644 --- a/Source/Pages/Photo/YPCameraView.swift +++ b/Source/Pages/Photo/YPCameraView.swift @@ -50,7 +50,15 @@ internal class YPCameraView: UIView, UIGestureRecognizerDelegate { } // Layout - let isIphone4 = UIScreen.main.bounds.height == 480 + var height: CGFloat = 0 + + if #available(iOS 13.0, *) { + height = window?.windowScene?.screen.bounds.height ?? .zero + } else { + height = UIScreen.main.bounds.height + } + + let isIphone4 = height == 480 let sideMargin: CGFloat = isIphone4 ? 20 : 0 if YPConfig.onlySquareImagesFromCamera { layout(