在 Swift 中使用 WatchKit 以编程方式设置 UIImage 动画
Programmatically Set UIImage Animation with WatchKit in Swift
我似乎无法弄清楚如何以编程方式为 UIImage 设置动画。
我看过 Objective-C 中写的代码,但在 Swift 中寻找解决方案。
我能找到的最接近的代码是:
imageView.startAnimatingWithImages(in: ???[NSRange] , duration: 1, repeatCount: 100)
但我不确定要在 NSRange 中放入什么。图像存储在我的资产文件夹中的一个文件夹中:
enter image description here
swift中的代码(但不适用于 Apple Watch):How to animate images in Swift?
Objective- C代码:
找到了一个swift解决方案:安静简单,我只需要添加一个图像出口并编写以下两个代码项:
class InterfaceController: WKInterfaceController {
@IBOutlet weak var imageObject: WKInterfaceImage!
override func awake(withContext context: Any?) {
super.awake(withContext: context)
imageObject.setImageNamed("plank")
imageObject.startAnimating()
// Configure interface objects here.
}
}
我似乎无法弄清楚如何以编程方式为 UIImage 设置动画。
我看过 Objective-C 中写的代码,但在 Swift 中寻找解决方案。
我能找到的最接近的代码是:
imageView.startAnimatingWithImages(in: ???[NSRange] , duration: 1, repeatCount: 100)
但我不确定要在 NSRange 中放入什么。图像存储在我的资产文件夹中的一个文件夹中: enter image description here
swift中的代码(但不适用于 Apple Watch):How to animate images in Swift?
Objective- C代码:
找到了一个swift解决方案:安静简单,我只需要添加一个图像出口并编写以下两个代码项:
class InterfaceController: WKInterfaceController {
@IBOutlet weak var imageObject: WKInterfaceImage!
override func awake(withContext context: Any?) {
super.awake(withContext: context)
imageObject.setImageNamed("plank")
imageObject.startAnimating()
// Configure interface objects here.
}
}