forked from shadowfacts/Tusker
Scale evenly in both dimensions in gallery animations
This commit is contained in:
parent
4fcc32ca4b
commit
c05107bccd
|
@ -43,9 +43,10 @@ class GalleryDismissAnimationController: NSObject, UIViewControllerAnimatedTrans
|
||||||
let appliedSourceToDestTransform: Bool
|
let appliedSourceToDestTransform: Bool
|
||||||
if destFrameInContainer.width > 0 && destFrameInContainer.height > 0 {
|
if destFrameInContainer.width > 0 && destFrameInContainer.height > 0 {
|
||||||
appliedSourceToDestTransform = true
|
appliedSourceToDestTransform = true
|
||||||
|
let scale = min(destFrameInContainer.width / sourceFrameInContainer.width, destFrameInContainer.height / sourceFrameInContainer.height)
|
||||||
let sourceToDestTransform = origSourceTransform
|
let sourceToDestTransform = origSourceTransform
|
||||||
.translatedBy(x: destFrameInContainer.midX - sourceFrameInContainer.midX, y: destFrameInContainer.midY - sourceFrameInContainer.midY)
|
.translatedBy(x: destFrameInContainer.midX - sourceFrameInContainer.midX, y: destFrameInContainer.midY - sourceFrameInContainer.midY)
|
||||||
.scaledBy(x: destFrameInContainer.width / sourceFrameInContainer.width, y: destFrameInContainer.height / sourceFrameInContainer.height)
|
.scaledBy(x: scale, y: scale)
|
||||||
sourceView.transform = sourceToDestTransform
|
sourceView.transform = sourceToDestTransform
|
||||||
} else {
|
} else {
|
||||||
appliedSourceToDestTransform = false
|
appliedSourceToDestTransform = false
|
||||||
|
|
|
@ -49,9 +49,11 @@ class GalleryPresentationAnimationController: NSObject, UIViewControllerAnimated
|
||||||
let origSourceTransform = sourceView.transform
|
let origSourceTransform = sourceView.transform
|
||||||
let sourceToDestTransform: CGAffineTransform?
|
let sourceToDestTransform: CGAffineTransform?
|
||||||
if destFrameInContainer.width > 0 && destFrameInContainer.height > 0 {
|
if destFrameInContainer.width > 0 && destFrameInContainer.height > 0 {
|
||||||
|
// Scale evenly in both dimensions, to prevent the source view appearing to stretch/distort during the animation.
|
||||||
|
let scale = min(destFrameInContainer.width / sourceFrameInContainer.width, destFrameInContainer.height / sourceFrameInContainer.height)
|
||||||
sourceToDestTransform = origSourceTransform
|
sourceToDestTransform = origSourceTransform
|
||||||
.translatedBy(x: destFrameInContainer.midX - sourceFrameInContainer.midX, y: destFrameInContainer.midY - sourceFrameInContainer.midY)
|
.translatedBy(x: destFrameInContainer.midX - sourceFrameInContainer.midX, y: destFrameInContainer.midY - sourceFrameInContainer.midY)
|
||||||
.scaledBy(x: destFrameInContainer.width / sourceFrameInContainer.width, y: destFrameInContainer.height / sourceFrameInContainer.height)
|
.scaledBy(x: scale, y: scale)
|
||||||
} else {
|
} else {
|
||||||
sourceToDestTransform = nil
|
sourceToDestTransform = nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ class ImageGalleryContentViewController: UIViewController, GalleryContentViewCon
|
||||||
|
|
||||||
imageView = GIFImageView(image: maybeGrayscaleImage)
|
imageView = GIFImageView(image: maybeGrayscaleImage)
|
||||||
imageView.translatesAutoresizingMaskIntoConstraints = false
|
imageView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
imageView.contentMode = .scaleAspectFit
|
imageView.contentMode = .scaleAspectFill
|
||||||
imageView.isUserInteractionEnabled = true
|
imageView.isUserInteractionEnabled = true
|
||||||
view.addSubview(imageView)
|
view.addSubview(imageView)
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
|
|
Loading…
Reference in New Issue