布局约束冲突默认今天的Widget

布局约束冲突默认今天的Widget

本文介绍了布局约束冲突默认今天的Widget的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我观察到关于在今天的Widget我只是为我的应用程序创建的自动布局一个非常奇怪的现象。
试图让我结束了创建一个简单的新的X code项目(单一视图的应用程序)的问题的根源,并增加了今天,扩展为新的目标 - 甚至没有触及它

I have observed a very strange behavior regarding Autolayout in the Today Widget I just created for my app.Trying to get to the root of the problem I ended up creating a plain new Xcode project (single view app) and added a Today Extension as a new target - without even touching it.

当我启动拓今天我的设备上(iPhone 6S)中发生的第一件事情就是布局约束冲突在控制台抛出:

When I launch the Today Extension on my device (iPhone 6s) the first thing that happens is that layout constraint conflicts are thrown in the console:

2016-05-03 18:17:22.216 TodayExtension[10183:4611907] 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.
(
    "<_UILayoutSupportConstraint:0x15c665320 V:[_UILayoutGuide:0x15c6657b0(0)]>",
    "<_UILayoutSupportConstraint:0x15c663890 V:|-(0)-[_UILayoutGuide:0x15c6657b0]   (Names: '|':UIView:0x15c6642a0 )>",
    "<_UILayoutSupportConstraint:0x15c666010 V:[_UILayoutGuide:0x15c666380(0)]>",
    "<_UILayoutSupportConstraint:0x15c666ed0 _UILayoutGuide:0x15c666380.bottom == UIView:0x15c6642a0.bottom>",
    "<NSLayoutConstraint:0x15c666b80 V:[_UILayoutGuide:0x15c6657b0]-(NSSpace(8))-[UILabel:0x15c6617c0'Hello World']>",
    "<NSLayoutConstraint:0x15c666bd0 V:[UILabel:0x15c6617c0'Hello World']-(NSSpace(8))-[_UILayoutGuide:0x15c666380]>",
    "<NSLayoutConstraint:0x15c552820 'UIView-Encapsulated-Layout-Height' V:[UIView:0x15c6642a0(0)]>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x15c666bd0 V:[UILabel:0x15c6617c0'Hello World']-(NSSpace(8))-[_UILayoutGuide:0x15c666380]>

您会注意到,在列表中的制约因素,最后一个是一个 UIView的封装,布局,高度这迫使0视图中的一个高度。我检查并推断所引用的观点是小部件的根视图本身。因此,出于某种原因,这是出乎我的COM prehension系统内部创建一个640像素的高度约束,在界面生成器视图的设置冲突。 (正如你将看到当您创建X code进行新的扩展今天没有什么存在,但一说的寄托widget的根视图的每一侧一个UILabel。)

You'll notice that the last one of the constraints in the list is a UIView-Encapsulated-Layout-Height which forces a height of 0 on the view. I checked and figured that the referenced view is the widget's root view itself. So for some reason that's beyond my comprehension the system internally creates a 0 pixel-height constraint that conflicts with the setup of the view in Interface Builder. (As you will see when you create a fresh today extension in Xcode there's nothing there but a a UILabel that's pinned to each side of the widget's root view.)

通常我会说,这是一个巨大的iOS错误,但因为这是苹果公司的默认的模板来创建窗口小部件今天我简直不敢相信这是打破。任何想法是什么导致了这种矛盾的行为,以及如何修复它(的正常的)?

Normally I would claim that this is a huge iOS bug but as this is Apple's default template for creating Today Widgets I just cannot believe it's broken. Any idea what's causing this conflicting behavior and how to fix it (properly)?

...是要弄清楚是否有可靠使用自动布局在今天的Widget的没有推出了几个解决方法和脏黑客你会不正常的应用程序内使用。的(如果你最终添加大量创造固定框架,不要让内容动态地成长,这不是真正的自动布局的想法,是约束?)

... is to figure out if there is a reliable way to use Autolayout in a Today Widget without introducing several workarounds and "dirty hacks" that you wouldn't use inside a normal app. (If you end up adding plenty of constraints that create fixed frames and don't let the content grow dynamically that's not really the idea of Autolayout, is it?)

密切相关的问题,这就是问题的一部分,可能会给一个提示:结果

Closely related question that's part of the problem and might give a hint:
Inconsistent Today Widget behavior breaks subview's height constraints

推荐答案

在某些苹果股票的的UIView 的子类,它们被实例化一个大小为零。你需要配置你的 NSLayoutConstraint 如此,他们可以适当地给这个初始大小反应。在过去,我做了顶部或底部的制约因素的不平等,使约束的其余部分可能本身的大小正确,不会打破布局。

In some of Apple's stock UIView subclasses, they are instantiated with a size of zero. You need to configure your NSLayoutConstraints so that they can properly react to this initial size. In the past, I've made top or bottom constraints an inequality so that the rest of the constraints may size themselves correctly and not break the layout.

例如:让你的底约束(&LT; NSLayoutConstraint:0x15c666bd0五:[的UILabel:0x15c6617c0'Hello世界'] - (NSSpace(8)) - [_ UILayoutGuide:0x15c666380&GT; )一个 LessThanOrEqualTo 与一个 8.0

Ex: Make your bottom constraint (<NSLayoutConstraint:0x15c666bd0 V:[UILabel:0x15c6617c0'Hello World']-(NSSpace(8))-[_UILayoutGuide:0x15c666380]>) a LessThanOrEqualTo with a constant value of 8.0.

这篇关于布局约束冲突默认今天的Widget的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 13:12