LottieAnimationView 尺寸不会 change/is 太小 (iOS/Swift)
LottieAnimationView size won't change/is too small (iOS/Swift)
无论我创建的视图是 LOTAnimatedSwitch 还是 View,动画的图像总是显得很小。 lottie 动画不会占用我创建的视图的大小。这是从 LottieFiles 下载动画的问题吗?文件的尺寸为 600x600 像素。我使用的是 Lottie 版本 2.5.0 和 Swift 4。例如:
let animatedSwitch = LOTAnimatedSwitch(named: "toggle_switch")
animatedSwitch.frame.origin = CGPoint(x: 8, y: separatorLineView.frame.height + separatorLineView.frame.origin.y + 8)
animatedSwitch.frame.size = CGSize(width: dialogViewWidth - 16, height: 40)
animatedSwitch.setProgressRangeForOnState(fromProgress: 0.5, toProgress: 1)
animatedSwitch.setProgressRangeForOffState(fromProgress: 0, toProgress: 0.5)
animatedSwitch.contentMode = .scaleAspectFill
animatedSwitch.clipsToBounds = true
animatedSwitch.backgroundColor = .purple
试试这个代码我不确定这对你的情况有帮助
let animatedSwitch = LOTAnimatedSwitch(named: "toggle_switch")
animatedSwitch.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
animatedSwitch.center = self.view.center
animatedSwitch.setProgressRangeForOnState(fromProgress: 0.5, toProgress: 1)
animatedSwitch.setProgressRangeForOffState(fromProgress: 0, toProgress: 0.5)
animatedSwitch.contentMode = .scaleAspectFit
self.view.addSubview(animatedSwitch)
self.view.backgroundColor = UIColor.lightGray
问题出在我从 LottieFiles 下载的文件上。为了避免 animation/icon 变小,我在 adobe after effects 中缩放了合成尺寸以适应预览框架。我使用 bodymovin 插件将 .aeb 文件导出到 .json。
Hardik 的回答也很有帮助。问题很简单,我下载的文件在实际图标周围有很多空白 space,直到我按比例放大图片。
animationView = .init(name: "lf30_editor_fip4qqkq")
animationView!.frame = CGRect(x: 0, y: 0, width: 150, height: 150)
animationView!.center = self.view.center
animationView!.contentMode = .scaleAspectFit
animationView!.loopMode = .loop
animationView!.animationSpeed = 1.0
view.addSubview(animationView!)
animationView!.play()
我也有这个问题。我将动画视图的宽度和高度修改为我想要的大小,并将内容模式更改为缩放纵横比填充。如果你想让动画变大,只需更新你的宽度和高度。这是示例代码。
animationView.animation = Animation.named("loading")
animationView.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
animationView.contentMode = .scaleAspectFill
animationView.loopMode = .loop
animationView.play()
无论我创建的视图是 LOTAnimatedSwitch 还是 View,动画的图像总是显得很小。 lottie 动画不会占用我创建的视图的大小。这是从 LottieFiles 下载动画的问题吗?文件的尺寸为 600x600 像素。我使用的是 Lottie 版本 2.5.0 和 Swift 4。例如:
let animatedSwitch = LOTAnimatedSwitch(named: "toggle_switch")
animatedSwitch.frame.origin = CGPoint(x: 8, y: separatorLineView.frame.height + separatorLineView.frame.origin.y + 8)
animatedSwitch.frame.size = CGSize(width: dialogViewWidth - 16, height: 40)
animatedSwitch.setProgressRangeForOnState(fromProgress: 0.5, toProgress: 1)
animatedSwitch.setProgressRangeForOffState(fromProgress: 0, toProgress: 0.5)
animatedSwitch.contentMode = .scaleAspectFill
animatedSwitch.clipsToBounds = true
animatedSwitch.backgroundColor = .purple
试试这个代码我不确定这对你的情况有帮助
let animatedSwitch = LOTAnimatedSwitch(named: "toggle_switch")
animatedSwitch.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
animatedSwitch.center = self.view.center
animatedSwitch.setProgressRangeForOnState(fromProgress: 0.5, toProgress: 1)
animatedSwitch.setProgressRangeForOffState(fromProgress: 0, toProgress: 0.5)
animatedSwitch.contentMode = .scaleAspectFit
self.view.addSubview(animatedSwitch)
self.view.backgroundColor = UIColor.lightGray
问题出在我从 LottieFiles 下载的文件上。为了避免 animation/icon 变小,我在 adobe after effects 中缩放了合成尺寸以适应预览框架。我使用 bodymovin 插件将 .aeb 文件导出到 .json。
Hardik 的回答也很有帮助。问题很简单,我下载的文件在实际图标周围有很多空白 space,直到我按比例放大图片。
animationView = .init(name: "lf30_editor_fip4qqkq")
animationView!.frame = CGRect(x: 0, y: 0, width: 150, height: 150)
animationView!.center = self.view.center
animationView!.contentMode = .scaleAspectFit
animationView!.loopMode = .loop
animationView!.animationSpeed = 1.0
view.addSubview(animationView!)
animationView!.play()
我也有这个问题。我将动画视图的宽度和高度修改为我想要的大小,并将内容模式更改为缩放纵横比填充。如果你想让动画变大,只需更新你的宽度和高度。这是示例代码。
animationView.animation = Animation.named("loading")
animationView.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
animationView.contentMode = .scaleAspectFill
animationView.loopMode = .loop
animationView.play()