2

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?

user6876645
  • 21
  • 1
  • 2
  • The values you are setting are not valid and might be causing a problem. You should use the `maxSize` variable when the display mode is `.Compact` and make sure the height you choose is not larger. Also, a width of 0 might be causing bugs, use the width of your view. – EmilioPelaez Oct 10 '16 at 02:53

3 Answers3

4

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

Constantin Saulenco
  • 2,353
  • 1
  • 22
  • 44
  • I'm updating the size of my widget by using a constraint for the height of a stack view, rather than relying on the preferredContentSize. I'm still getting the error message despite I don't touch that property at all in my implementation. I also get the "Failed to inherit CoreMedia permissions from … (null)" error before the "No active animation block!" error. – valeCocoa Sep 07 '17 at 23:13
4

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)
    }
}
Jacolack
  • 1,365
  • 2
  • 11
  • 25
odemolliens
  • 2,581
  • 2
  • 32
  • 34
1

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

Siyuan Hao
  • 11
  • 2