今日扩展:如何使用显示模式? [英] Today Extension: How to work with display mode?
本文介绍了今日扩展:如何使用显示模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
小部件现在包括显示模式的概念(由 NCWidgetDisplayMode 表示)您描述了有多少可用的内容,并允许用户选择紧凑的视图或展开的视图.
Widgets now include the concept of display mode (represented by NCWidgetDisplayMode), which lets you describe how much content is available and allows users to choose a compact or expanded view.
如何在ios 10.0中扩展小部件?它无法在ios 9中正常工作.
How to expand widget in ios 10.0? It doesn't work as in ios 9.
推荐答案
Ok, i found right solution here.
1)首先在viewDidLoad
中将显示模式设置为NCWidgetDisplayMode.expanded
:
1) Set the display mode to NCWidgetDisplayMode.expanded
first in viewDidLoad
:
override func viewDidLoad() {
super.viewDidLoad()
self.extensionContext?.widgetLargestAvailableDisplayMode = NCWidgetDisplayMode.expanded
}
2)实施新的协议方法:
2) Implement new protocol method:
func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
if (activeDisplayMode == NCWidgetDisplayMode.compact) {
self.preferredContentSize = maxSize
}
else {
//expanded
self.preferredContentSize = CGSize(width: maxSize.width, height: 200)
}
}
它将作为官方应用程序运行.
And it will work as official apps.
这篇关于今日扩展:如何使用显示模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文