-1

I know this type of question has been asked before, but none of them is able to solve my problem.

I want to set the Today's Extension height to be variable.

For this I have included the below code as suggested in related posts:

override func viewDidLoad()
    {
        super.viewDidLoad()

        if #available(iOSApplicationExtension 10.0, *)
        {
            self.extensionContext?.widgetLargestAvailableDisplayMode = .expanded
        }
        else
        {
            // Fallback on earlier versions
        }
    }

@available(iOSApplicationExtension 10.0, *)
    func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize)
    {
        if activeDisplayMode == .expanded
        {
            preferredContentSize = CGSize(width: 0.0, height: 200.0)
        }
        else
        {
            preferredContentSize = maxSize
        }
    }

The problem I am facing is, even after setting widgetLargestAvailableDisplayMode to .expanded in viewDidLoad, when the protocol method widgetActiveDisplayModeDidChange is called, it is still giving me the activeDisplayMode as .compact.

What else need to be done to make the widget work right in iOS 10?

4

1 回答 1

0

I figured it out.

Actually when the widget is loaded for the first time, it is by default in the compact mode and so widgetActiveDisplayModeDidChange is called with activeDisplayMode as .compact.

After loading,

  1. When Show More button is pressed, widgetActiveDisplayModeDidChange is called with activeDisplayMode as .expanded.

  2. When Show Less button is pressed, widgetActiveDisplayModeDidChange is called with activeDisplayMode as .compact.

于 2017-02-21T16:43:58.780 回答