Apple文档建议使用autolayout设置Today Extensions的高度.
如果窗口小部件具有要显示的其他内容,则可以依赖"自动布局"约束来适当调整窗口小部件的高度.如果不使用自动布局,则可以使用UIViewController属性preferredContentSize指定窗口小部件的新高度.
但是,我见过的每个示例和教程最终都会使用preferredContentSize.
我通过autolayout设置高度的所有尝试都会导致违反约束的警告.
我开始使用新的xcode模板和一个全新的扩展模板.我添加的唯一内容TodayViewController.m是:
- (UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets {
return UIEdgeInsetsMake(0, 0, 0, 0);
}
Run Code Online (Sandbox Code Playgroud)
注意:如果我只使用默认边距,我仍会遇到此问题.
我约束标签高度,将标签置于容器中心,并将容器高度限制为与标签高度相同:

这应该导致一个标签在指定的高度填充容器,没有约束冲突.相反,我得到一个约束冲突:
2014-09-28 10:27:39.254 TodayExtension[61090:2672196] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're …Run Code Online (Sandbox Code Playgroud)