You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please, document setShouldResizeFrames() in the Readme.
It is the only way to adapt the gif size to the screen scale (in case of the retina displays). And it is one of the main advantages of this library against the others, that in general they do not support gif resizing.
It is useful to highlight the scaling possibility to the retina displays, so the devs are aware that it is not automatically supported, but can be implemented easily.
The needed steps are:
Read the @1x gif into a UIImage and get the frame.size.
Set the size of the GIFImageView to the previous obtained size, scaling it using UIScreen.main.scale.
Add the line setShouldResizeFrames(true).
Pass the @2x or @3x file names to prepareForAnimation depending on UIScreen.main.scale.
Example:
extension GIFImageView {
func customPrepareForAnimation(withGIFNamed imageName: String, loopCount: Int = 1) {
let scale = UIScreen.main.scale
var scaledImageName = imageName
if Int(scale) == 2 {
scaledImageName += "@2x"
} else if Int(scale) >= 3 {
scaledImageName += "@3x"
}
if let url = Bundle.main.url(forResource: scaledImageName, withExtension: "gif"), let data = try? Data(contentsOf: url), let image = UIImage(data: data) {
frame = CGRect(x: 0, y: 0, width: image.size.width / scale, height: image.size.height / scale)
setShouldResizeFrames(true)
} else {
assertionFailure("Imposible to load \(scaledImageName).gif from main bundle. Check the resource name and try again")
}
prepareForAnimation(withGIFNamed: scaledImageName, loopCount: loopCount)
}
}
The text was updated successfully, but these errors were encountered:
Please, document
setShouldResizeFrames()
in the Readme.It is the only way to adapt the gif size to the screen scale (in case of the retina displays). And it is one of the main advantages of this library against the others, that in general they do not support gif resizing.
It is useful to highlight the scaling possibility to the retina displays, so the devs are aware that it is not automatically supported, but can be implemented easily.
The needed steps are:
UIImage
and get theframe.size
.UIScreen.main.scale
.setShouldResizeFrames(true)
.prepareForAnimation
depending onUIScreen.main.scale
.Example:
The text was updated successfully, but these errors were encountered: