ios - 使用自动布局为 iOS8 今日扩展设置固定高度

标签 ios ios8 autolayout today-extension

我正在尝试实现一个简单的今天小部件,其中包含一个固定高度的标签。

在文档中它说:

If a widget has additional content to display, you can rely on Auto Layout constraints to adjust the widget’s height as appropriate.

但是我不断收到“无法同时满足约束条件”的警告。

这是我尝试过的:

  1. 创建一个新的“Today Extension”目标,它会创建带有“Hello World”标签和 View Controller 的 Storyboard。
  2. 将高度限制设置为“Hello World”标签。

enter image description here

当我运行时,我得到:

2014-09-18 21:13:07.123 TestWidget[23381:871330] 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 seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x7f87c31126d0 V:[UILabel:0x7f87c3113230'Hello World Fixed Height'(21)]>",
    "<NSLayoutConstraint:0x7f87c30235b0 V:[_UILayoutGuide:0x7f87c30222b0]-(NSSpace(8))-[UILabel:0x7f87c3113230'Hello World Fixed Height']>",
    "<NSLayoutConstraint:0x7f87c3023600 V:[UILabel:0x7f87c3113230'Hello World Fixed Height']-(NSSpace(8))-[_UILayoutGuide:0x7f87c3022f00]>",
    "<_UILayoutSupportConstraint:0x7f87c3021980 V:[_UILayoutGuide:0x7f87c30222b0(0)]>",
    "<_UILayoutSupportConstraint:0x7f87c30218a0 V:|-(0)-[_UILayoutGuide:0x7f87c30222b0]   (Names: '|':UIView:0x7f87c3112f20 )>",
    "<_UILayoutSupportConstraint:0x7f87c3023360 V:[_UILayoutGuide:0x7f87c3022f00(0)]>",
    "<_UILayoutSupportConstraint:0x7f87c3023300 _UILayoutGuide:0x7f87c3022f00.bottom == UIView:0x7f87c3112f20.bottom>",
    "<NSLayoutConstraint:0x7f87c3326710 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7f87c3112f20(628)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f87c31126d0 V:[UILabel:0x7f87c3113230'Hello World Fixed Height'(21)]>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

我做错了什么?使用自动布局创建具有固定高度的小部件的正确方法是什么?

最佳答案

我找到了一种方法来消除这些警告,方法是引入包装 View ,将所有其他 View 放入该包装 View 中,并将包装 View 的高度限制设置为低优先级。

snapshot

关于ios - 使用自动布局为 iOS8 今日扩展设置固定高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25926517/

相关文章:

ios - 非常基本的自动布局

cocoa - NSToolbar insertItemWithItemIdentifier :atIndex: call results in "Unable to simultaneously satisfy constraints" exception

ios - 不在状态栏中显示位置服务图标但仍使用后台更新

ios - 获取经典蓝牙连接设备列表(无BLE)[EAAccessoryManager]

ios - 禁止 UITableViewcontroller 横向旋转(保持纵向)

video-streaming - 使用视频工具箱在 iOS 8 中解码 h264

ios - iOS中从中央服务器查询大量数据的建议

ios - RxCocoa-observable 正在从 API 发出新数据,但 tableview.rx.items 不显示新数据

ios - 如何快速增加 ScrollView 中的 UITableView 高度

ios - (iOS) 同时自动收缩 2 个相互约束的标签