I want to programmatically change the height of today's extension. When the IOS10 SDSK introduced NCWidgetDisplayMode, I try to use it to programmatically change my height preferredContentSize.
I implemented widgetActiveDisplayModeDidChange:
@available(iOSApplicationExtension 10.0, *)
func widgetActiveDisplayModeDidChange(activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
if (activeDisplayMode == NCWidgetDisplayMode.Compact) {
self.preferredContentSize = maxSize
}
else {
self.preferredContentSize = CGSize(width: maxSize.width, height: 280)
}
}
I want the height of the widget to expand when clicked UIButton:
@IBAction func multiplybyonethousand (sender: AnyObject) {
if self.extensionContext?.widgetActiveDisplayMode == NCWidgetDisplayMode.Compact {
self.widgetActiveDisplayModeDidChange(.Expanded, withMaximumSize: CGSizeMake(0, 300))
}
}
However, when I run my code, the height of today's extension does not change, and the console gives me the following error:
2016-11-05 14:24:29.425697 todayextension[28590:7222420] No active animation block!
I tried calling widgetActiveDisplayModeDidChangeinside the animation block:
@IBAction func multiplybyonethousand (sender: AnyObject) {
if self.extensionContext?.widgetActiveDisplayMode == NCWidgetDisplayMode.Compact {
UIView.animateWithDuration(0.2, delay: 0, options: .CurveLinear, animations: { () -> Void in
self.widgetActiveDisplayModeDidChange(.Expanded, withMaximumSize: CGSizeMake(0, 300))
}) { (completed) -> Void in
}
}
}
But I still get the error message No active animation block!. Is there a way to programmatically expand an existing kind of extension in iOS10?