Reputation: 21
I have implemented the new widget for iOS 10 and I have used the following code to set the height for it:
@available(iOSApplicationExtension 10.0, *)
func widgetActiveDisplayModeDidChange(activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
if activeDisplayMode == NCWidgetDisplayMode.Compact {
self.preferredContentSize = CGSizeMake(0.0, 350.0)
}
else if activeDisplayMode == NCWidgetDisplayMode.Expanded {
self.preferredContentSize = desiredSize
}
}
And it´s working fine, but my issue is with the "Show more" and "Show less" buttons. They don't always respond and I do very often have to click more than once to trigger them. I´m I missing something? Do I have to add more than the above code to handle the height?
Upvotes: 2
Views: 3487
Reputation: 2641
Swift 3:
func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
if (activeDisplayMode == NCWidgetDisplayMode.compact) {
UIView.animate(withDuration: 0.25, animations: { () -> Void in
self.preferredContentSize = yourFixSize
}, completion: nil)
}
else {
UIView.animate(withDuration: 0.25, animations: { () -> Void in
self.preferredContentSize = yourMaxSize
}, completion: nil)
}
}
Upvotes: 4
Reputation: 2383
I had the same issue , the problem was that i had updated the preferredContentSize
even if the widget was in the compact mode.
Try to check every place where you update the preferredContentSize
and update the size only if the if widgetActiveDisplayMode
is NCWidgetDisplayModeExpanded
Upvotes: 4
Reputation: 11
had same problem , and I found that when we click the "show more" “show less” button , there is no animation. So you can try to add a block like this :
- (void)widgetActiveDisplayModeDidChange:(NCWidgetDisplayMode)activeDisplayMode withMaximumSize:(CGSize)maxSize {
if (activeDisplayMode == NCWidgetDisplayModeCompact) {
[UIView animateWithDuration:0.25f
animations:^{
self.preferredContentSize = yourFixSize; }];
}
else {
[UIView animateWithDuration:0.25f
animations:^{
self.preferredContentSize = yourMaxSize;
}];
}
}
I fix this bug in this way .
Hope useful
Upvotes: 1