我是初学者,我有点理解Lazy Var vs. Let.我注意到,当使用Lazy Var时,特别是使用ImageViews,可以节省大量的内存使用量.但是到目前为止我看过的教程和指南并没有经常使用Lazy Var,所以我很怀疑它是不好的做法而且我忽略了一些东西.
我做了一点研究,得知Lazy不是"线程安全",但我不明白这意味着什么.我已经看到了很多优点和缺点,但我无法得出任何结论,特别是因为我的知识非常有限.
什么时候(或更好)在创建UIView时使用Lazy Var vs. Let?
lazy var profileImageView: UIImageView = {
let imageView = UIImageView(image: #imageLiteral(resourceName: "page1"))
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.contentMode = .scaleAspectFit
return imageView
}()
Run Code Online (Sandbox Code Playgroud) 无论我创建的视图是 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
Run Code Online (Sandbox Code Playgroud)