如何在iOS 11中调整窗口小部件的高度?
我无法调整今天Extension的高度。
SalesDeal
答案 0 :(得分:1)
有点猜测,但试试这个(使用maxSize.width
而不是0宽度):
func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
if activeDisplayMode == NCWidgetDisplayMode.compact {
//compact
self.preferredContentSize = maxSize
} else {
//extended
self.preferredContentSize = CGSize(width: maxSize.width, height: 200)
}
}
另外,请勿忘记添加此行以启用.expanded
模式(例如,viewDidLoad
):
self.extensionContext?.widgetLargestAvailableDisplayMode = .expanded
答案 1 :(得分:1)
我写入didReceiveMemoryWarning但正确的是写入viewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
self.extensionContext?.widgetLargestAvailableDisplayMode = NCWidgetDisplayMode.expanded}
func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
if activeDisplayMode == NCWidgetDisplayMode.compact {
//compact
self.preferredContentSize = maxSize
} else {
//extended
self.preferredContentSize = CGSize(width: 0, height: 200)
}