iOS10 widget “Show more” “Show less” bug

蹲街弑〆低调 提交于 2019-12-11 02:11:26

问题


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?


回答1:


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




回答2:


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)
    }
}



回答3:


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



来源:https://stackoverflow.com/questions/39683238/ios10-widget-show-more-show-less-bug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!