I'd like to write a Today Widget Extension with an UIImageView which display an animation.
Here are my code.
override func viewDidLoad() {
super.viewDidLoad()
layoutComponents()
imageView.startAnimating()
}
func layoutComponents() {
self.extensionContext?.widgetLargestAvailableDisplayMode = NCWidgetDisplayMode.expanded
self.view.backgroundColor = UIColor.blue
let images = [UIImage(named:"1.png"), UIImage(named:"2.png"), UIImage(named:"3.png")]
imageView.frame = CGRect(x: 0, y: 0, width: self.extensionContext!.widgetMaximumSize(for: .expanded).width, height: self.extensionContext!.widgetMaximumSize(for: .expanded).height)
imageView.animationImages = images
imageView.image = images[0]
imageView.animationDuration = 1.0
imageView.animationRepeatCount = 0
self.view.addSubview(imageView)
debugPrint("Done LayoutComponents")
}
The code compiled successfully. However, the widget cannot be loaded, it display "Unable to Load" on the widget when run on the iPhone. And in the debug print, after printing "Done LayoutComponents". It has a line "Program ended with exit code: 0".
Any clues what i have done wrong? thanks.
Note that whenever i put the code imageView.startAnimating() in either viewWillAppear() viewDidAppear or widgetPerformUpdate() it will exit and with the problem that "Unable to load".
My question is actually is Today Extension support animating an UIImageView?