新的iOS 10 Today Widget / Extension的高度是多少? [英] What is the height of the new iOS 10 Today Widget/Extension?

查看:449
本文介绍了新的iOS 10 Today Widget / Extension的高度是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建iOS Today小部件,在测试iOS 10时,我注意到所有小部件现在都被赋予相同的高度(之前的版本允许开发人员设置高度)。什么是理想高度/处理这个新限制的最佳做法是什么?我很快,我没有使用autolayout fyi。提前致谢!

I am building an iOS Today widget, and while testing for iOS 10 I noticed that all widgets are now being given the same height (previous versions allowed the dev to set the height). What is the ideal height/what is the best practice for dealing with this new limitation? I'm in swift and I didn't use autolayout fyi. Thanks in advance!

推荐答案

在iOS 10中,默认情况下,今天小部件的高度是固定的。此外,折叠小部件的最小高度是有限的。

In iOS 10, by default, the height of today widget is fixed. Moreover, the minimum height of collapsed widget is limited.


折叠小部件是大约两个半表行的高度。理想情况下,扩展的小部件不会高于屏幕的高度。

A collapsed widget is the height of roughly two and a half table rows. An expanded widget is ideally no taller than the height of the screen.

这些笔记来自iOS人机界面指南

我们可以执行以下操作更改它。

We can do the following to change it.

首先,您需要在 viewDidLoad 中添加这些代码,这会使您的小部件支持两种模式是iOS 10中的新功能。

First of all, you need to add these codes in your viewDidLoad, this makes your widget supports two modes which are new in iOS 10.

if #available(iOSApplicationExtension 10.0, *) { // Xcode would suggest you implement this.
    extensionContext?.widgetLargestAvailableDisplayMode = .expanded
} else {
    // Fallback on earlier versions
}



ObjC版本:



ObjC Version:

self.extensionContext.widgetLargestAvailableDisplayMode = NCWidgetDisplayModeExpanded;

然后执行协议方法,如:

And then implement the protocol method like:

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



ObjC版本:



ObjC Version:

- (void)widgetActiveDisplayModeDidChange:(NCWidgetDisplayMode)activeDisplayMode withMaximumSize:(CGSize)maxSize {
    if (activeDisplayMode == NCWidgetDisplayModeExpanded) {
        self.preferredContentSize = CGSizeMake(0.0, 200.0);
    } else if (activeDisplayMode == NCWidgetDisplayModeCompact) {
        self.preferredContentSize = maxSize;
    }
}

运行你的目标,你会看到显示更多小部件右上角的按钮。点按它即可看到更改。

Run your target, you will see a "Show More" button on right corner of your widget. Tap it and you will see the change.

查看更多详细信息:如何调整iOS 10中小部件的高度?

这篇关于新的iOS 10 Today Widget / Extension的高度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆