ios - Change NCWidgetDisplayMode programmatically in IOS10 Widget -
i looking programmatically change height of today extension. ios10 sdsk introduced ncwidgetdisplaymode
trying use programmatically change height of preferredcontentsize
.
i have 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 widget height expand when uibutton
pressed :
@ibaction func multiplybyonethousand (sender: anyobject) { if self.extensioncontext?.widgetactivedisplaymode == ncwidgetdisplaymode.compact { self.widgetactivedisplaymodedidchange(.expanded, withmaximumsize: cgsizemake(0, 300)) } }
however when run code, height of today extension not change , console gives me following error:
2016-11-05 14:24:29.425697 todayextension[28590:7222420] no active animation block!
i have tried call widgetactivedisplaymodedidchange
inside 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 //do stuff } } }
but still no active animation block!
error message. there way programmatically expand today extension view in ios10 ?
in ios 10
, show more/show less
button automatically provided in today's extension
. height of widget
handled automatically through ncwidgetdisplaymode
. don't need provide explicit button handling widget's height.
override func viewdidload() { super.viewdidload() if #available(iosapplicationextension 10.0, *) { self.extensioncontext?.widgetlargestavailabledisplaymode = .expanded } }
implement ncwidgetproviding
protocol's method:
@available(iosapplicationextension 10.0, *) func widgetactivedisplaymodedidchange(_ activedisplaymode: ncwidgetdisplaymode, withmaximumsize maxsize: cgsize) { if activedisplaymode == .expanded { preferredcontentsize = cgsize(width: maxsize.width, height: 300) } else { preferredcontentsize = maxsize } }
in, ios 8
, ios 9
, need explicitly handle widget's height. in ios 10
, not required.
you can refer https://github.com/pgpt10/today-widget on today's widget
implementation in ios 8
, ios 9
, ios 10
.
Comments
Post a Comment