Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use UIApplication and view.windowScene.screen instead of UIScreen.main on iOS 13.0 and later #93

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions PryntTrimmerViewExample/VideoCropperViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? 1.0
} 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)
}
Expand Down
11 changes: 10 additions & 1 deletion Sources/PryntTrimmerView/Parents/AssetVideoScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? 1.0
} else {
scale = UIScreen.main.scale
}

let scaledSize = CGSize(width: maximumSize.width * scale, height: maximumSize.height * scale)
generator?.maximumSize = scaledSize
var count = 0

Expand Down
12 changes: 11 additions & 1 deletion Sources/PryntTrimmerView/ThumbSelectorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? 1.0
} else {
scale = UIScreen.main.scale
}

let side = thumbView.frame.height * ratio * scale
return CGSize(width: side, height: side)
}

Expand Down