如何设置今日窗口小部件扩展的高度? [英] How to set the height of a Today Widget Extension?

查看:142
本文介绍了如何设置今日窗口小部件扩展的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在通知中心更改应用程序的今日扩展程序的高度?

How can i change the height of my App's Today Extension in the Notification Center?

我尝试使用Interface Builder和代码,
界面生成器显示高度为600的视图,但它没有在设备上应用此高度。

I tried it with the Interface Builder and with Code, the Interface Builder Displays the View with height 600, but it's not applying this height on the device.

似乎我无法让它大于80像素...

It seems I can't get it bigger than some 80 pixels...

推荐答案

在你的小部件 UIViewController.m (Objective-C):

In your widget UIViewController.m (Objective-C):

self.preferredContentSize = CGSizeMake(0, 200);

将使您的小部件高度为200.

Will make your widget have a height of 200.

请注意,宽度对视图没有影响,因为小部件必须符合通知中心的确切宽度,这是自动处理的。

Note that the width will have no affect on the view, as widgets must fit in the exact width of notification center, which is handled automagically.

此外,如果你想对视图高度的变化进行动画处理,你可以实现(Objective-C):

Also, if you want to animate changes in the height of your view, you can implement (Objective-C):

- (void)viewWillTransitionToSize:(CGSize)size
       withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator

在你的使用 -animateAlongsideTransition查看控制器:完成:

in your view controller using -animateAlongsideTransition:completion:

答案有点隐藏;您必须在文档侧栏中单击以最终找到这个梦幻般的文件

The answer was a bit hidden; you had to click around in the documentation sidebar to eventually find this fantastic document.


另一种方法是使用自动布局限制以限制视图的高度。

Another way is to use auto-layout constraints to constrain your view's height.

这篇关于如何设置今日窗口小部件扩展的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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