【发布时间】:2019-11-05 10:35:52
【问题描述】:
如何使用 SwiftUI 框架为一系列图像(比如 Frame-1.png 到 Frame-6)制作动画?
我尝试过创建一个“图像”数组。然后我将 UIImage.animatedImage(with: images, duration: 1.0) 方法分配给一个名为“animatedImage”的变量 最后我在“ContentView.swift”的“body”中尝试了 Image(uiImage: animatedImage)
var images: [UIImage]! = [UIImage(named: "Sequence/frame-1")!,
UIImage(named: "Sequence/frame-2")!,
UIImage(named: "Sequence/frame-3")!,
UIImage(named: "Sequence/frame-4")!,
UIImage(named: "Sequence/frame-5")!,
UIImage(named: "Sequence/frame-6")!
]
let animatedImage : UIImage! = UIImage.animatedImage(with: images, duration: 1.0)
//////Then in the ContentView.swift I've tried this code:
struct ContentView : View {
var body: some View {
Image(uiImage: animatedImage)
}
}
当我运行程序时,它只显示第一帧,但我期望帧的动画
【问题讨论】:
标签: ios swift xcode animation swiftui