0

I'm attempting to implement an alpha change when the today widget expands so the data shows up but I can't seem to get it to animate at all. I'm attempting this on the simulator. Instead, it just appears with no animation at all.

-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator{

    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];

    [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context){

        (self.expandingLabel.alpha == 1) ? (self.expandingLabel.alpha = 0) : (self.expandingLabel.alpha = 1);

    } completion:Nil];


}

Can't see what I'm doing wrong. Would this method still work in iOS 8/9?

Also another concern I have is that I'd like to show additional data only when the widget is expanded. The way I'm handling this is that on iOS 10 I've determined that the minimum height I can have for a widget when closed is roughly 100 pixels. So in the storyboard I'm putting all the "extra" information below 100 pixels. Is this the correct way? Or is there a better way. I'll eventually carry this over to iOS 8 and iOS 9, but first I'd like to get this working first.

user1416564
  • 401
  • 5
  • 18

1 Answers1

1

In iOS 10, you can change the alpha of the expandingLabel whenever the widget's display mode is changed. i.e. when widgetActiveDisplayModeDidChange is called.

func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize)
{
    if activeDisplayMode == .expanded
    {
        preferredContentSize = CGSize(width: 0.0, height: 200.0) //Size of the widget you want to show in expanded mode
    }
    else
    {
        preferredContentSize = maxSize
    }
    UIView.animate(withDuration: 0.5, animations: {
        (self.expandingLabel.alpha == 1) ? (self.expandingLabel.alpha = 0) : (self.expandingLabel.alpha = 1)
    })
}
PGDev
  • 23,751
  • 6
  • 34
  • 88