Fix asset preview size

This commit is contained in:
Shadowfacts 2020-03-14 23:32:54 -04:00
parent 1ccb450477
commit 0691c3b9d6
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 14 additions and 1 deletions

View File

@ -170,12 +170,22 @@ class AssetCollectionViewController: UICollectionViewController {
return nil return nil
} else { } else {
let asset = fetchResult.object(at: indexPath.row - 1) let asset = fetchResult.object(at: indexPath.row - 1)
return UIContextMenuConfiguration(identifier: nil, previewProvider: { () -> UIViewController? in return UIContextMenuConfiguration(identifier: indexPath as NSIndexPath, previewProvider: { () -> UIViewController? in
return AssetPreviewViewController(asset: asset) return AssetPreviewViewController(asset: asset)
}, actionProvider: nil) }, actionProvider: nil)
} }
} }
override func collectionView(_ collectionView: UICollectionView, previewForHighlightingContextMenuWithConfiguration configuration: UIContextMenuConfiguration) -> UITargetedPreview? {
if let indexPath = (configuration.identifier as? NSIndexPath) as IndexPath?, let cell = collectionView.cellForItem(at: indexPath) {
let parameters = UIPreviewParameters()
parameters.backgroundColor = .black
return UITargetedPreview(view: cell, parameters: parameters)
} else {
return nil
}
}
// MARK: - Interaction // MARK: - Interaction
@objc func donePressed() { @objc func donePressed() {

View File

@ -63,6 +63,7 @@ class AssetPreviewViewController: UIViewController {
PHImageManager.default().requestImage(for: asset, targetSize: view.bounds.size, contentMode: .aspectFit, options: options) { (image, _) in PHImageManager.default().requestImage(for: asset, targetSize: view.bounds.size, contentMode: .aspectFit, options: options) { (image, _) in
DispatchQueue.main.async { DispatchQueue.main.async {
imageView.image = image imageView.image = image
self.preferredContentSize = image!.size
} }
} }
} }
@ -90,6 +91,7 @@ class AssetPreviewViewController: UIViewController {
livePhotoView.topAnchor.constraint(equalTo: self.view.topAnchor), livePhotoView.topAnchor.constraint(equalTo: self.view.topAnchor),
livePhotoView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor) livePhotoView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor)
]) ])
self.preferredContentSize = livePhoto.size
} }
} }
} }
@ -111,6 +113,7 @@ class AssetPreviewViewController: UIViewController {
player.play() player.play()
playerController.player = player playerController.player = player
self.embedChild(playerController) self.embedChild(playerController)
self.preferredContentSize = item.presentationSize
} }
} }
} }