8

Had updated the today's extension for iOS 10 implement the delegate method:

-(void)widgetActiveDisplayModeDidChange:(NCWidgetDisplayMode)activeDisplayMode withMaximumSize:(CGSize)maxSize
{
    if (activeDisplayMode == NCWidgetDisplayModeCompact){
        [UIView animateWithDuration:0.25 animations:^{
            self.preferredContentSize = maxSize;
            [self.view layoutIfNeeded];
        }];
    }
    else if (activeDisplayMode == NCWidgetDisplayModeExpanded){
        newHeight = [self getNewWidgetHeight];
        [UIView animateWithDuration:0.25 animations:^{
            self.preferredContentSize = CGSizeMake(0, newHeight);
            [self.view layoutIfNeeded];
        }];
    }
}

everything work fine. But if I leave the widget in compact mode (with show more option available) and if i rerun/reopen the widget screen and if i tapped on Show More button nothing happens even if the delegate method is triggered. I should press 2 time show more/less until widget starts expanding. I also receive this error:No active animation block!

Constantin Saulenco
  • 2,353
  • 1
  • 22
  • 44

2 Answers2

14

I found the issue.

I had edited the self.preferredContentSize even if the widget was in the compact mode.Just check every time when you update the preferredContentSize if widgetActiveDisplayMode is NCWidgetDisplayModeExpanded

Constantin Saulenco
  • 2,353
  • 1
  • 22
  • 44
  • 1
    Were you able to get rid of "No active animation block!" message in log? I also see it, but have no idea what it means. – jesse Jan 23 '17 at 13:35
  • no , :( i even override viewWillTransitionToSize:withTransitionCoordinator: but no success – Constantin Saulenco Jan 25 '17 at 09:09
  • @jesse Regarding the "No active animation block!" message. Make sure you do not call manual widget height update anywhere in the code for iOS10+. It's still needed for previous versions though. – nsuinteger Apr 19 '17 at 02:29
  • @nsuinteger What do you mean by manual widget height update? I change preferredContentSize in widgetActiveDisplayModeDidChange. Should I do this another way? – jesse Apr 19 '17 at 14:24
  • @jesse yeah only change the preferredContentSize in delegate callback i.e. widgetActiveDisplayModeDidChange for iOS10. Prior to iOS10 we used to set this property elsewhere to support dynamic height based on content displayed. But with iOS10, we had to carefully eliminate setting this property elsewhere as auto-layout takes care of that with delegateCallback. Since then the message "No active animation block!" went away. Cheers! – nsuinteger Apr 20 '17 at 12:42
  • @nsuinteger I never used it in other places. It must be something else. – jesse Apr 20 '17 at 16:22
  • @jessee it is something different: as soon as the viewDidLoad the delegate receives the widgetActiveDisplayMode: notification, and you are animating in that method despite the view has not yet appeared. To avoid that error you should check if the view is animating and then add those animations, otherwise do those changes without animating – valeCocoa Aug 31 '17 at 18:57
  • @vale I don't make any animations explicitly. I just set preferredContentSize property. – jesse Oct 04 '17 at 13:16
  • @jesse I am still having that error logged, despite I don't even use preferredContentSize at all, but rather an auto layout constraint on my view to make it change size between the two stages in widgetActiveDisplayModeDidChange:withMaximumSize: – valeCocoa Oct 05 '17 at 14:18
2

I was having the same issue and then checking out the storyboard I realized that the setting "User Preferred Explicit Size" was enabled.

enter image description here

Disabling that option worked for me.

Daniel Rivera
  • 227
  • 2
  • 7