今天不一致的Widget行为打破了子视图的身高限制 [英] Inconsistent Today Widget behavior breaks subview's height constraints

查看:117
本文介绍了今天不一致的Widget行为打破了子视图的身高限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题是关系到我刚刚发布#2另一个问题:结果
布局约束冲突默认今天的Widget

This question is related to another question I just posted on Stackoverflow:
Layout Constraint Conflicts in Default Today Widget

我添加了一个如今扩展为目标,以我的应用程序,删除默认的Hello World的标签,这是小部件的根视图中,并在其位置添加了一个普通的的UIView 。我给视图中的黄色,将其固定到根视图的所有边缘 - 以同样的方式在标签受到限制。然后我又增加了约束,以黄色的观点,以给它的100px的一个固定的高度。

I added a Today Extension as a target to my app, removed the default "Hello World" label that's inside the widget's root view and added a plain UIView in its place. I gave the view a yellow color and pinned it to all edges of the root view - the same way the label was constrained. Then I added another constraint to the yellow view in order to give it a fixed height of 100px.

窗口小部件故事板

当我启动的应用程序(模拟器上测试的的装置),高度约束会被忽略并黄色的观点占据了整个可用空间一路下跌至下一个小部件的头

When I launch the app (tested on simulator and device) that height constraint is simply ignored and the yellow view takes up the whole available space all the way down to the header of the next widget.

当我刷卡通知中心和拉下来又认为突然跳(这似乎是它的突然看到自己的高度约束)的小部件的底部留下39px的垂直空格:

When I swipe the notification center up and pull it down again the view suddenly jumps (it seems like it's suddenly "seeing" its own height constraint) leaving a vertical blank space of 39px at the bottom of the widget:

首次启动

我想,在 39px保证金是在底部是默认底部边缘今天小部件由 defaultMarginInsets widgetMarginInsetsForProposedMarginInsets(defaultMarginInsets:UIEdgeInsets)参数方法,我可以通过重写此方法并提供我自己的保证金插图修复此不一致的行为:

I figured that the 39px margin at the bottom is the default bottom margin of a today widget as passed in by the defaultMarginInsets parameter in the widgetMarginInsetsForProposedMarginInsets(defaultMarginInsets: UIEdgeInsets) method and that I can fix this inconsistent behavior by overriding this method and providing my own margin insets:

func widgetMarginInsetsForProposedMarginInsets(defaultMarginInsets: UIEdgeInsets) -> UIEdgeInsets {
    var newInsets = defaultMarginInsets
    newInsets.bottom = 20
    return newInsets
}

不过,我真的preFER使用系统提供的利润,而不是固定值。在我看来,这样是对于今天小部件在其他iOS的bug。是吗?如果不是:我怎样才能解决这个问题。

However, I would really prefer to use system provided margins instead of fixed values. It seems to me like this is another iOS bug regarding the today widget. Is it? And if not: How can I fix this?

推荐答案

尽量避免使用针。

有关定位,依赖于你的看法对准了上海华领先,落后,顶部或底部边缘。

For positioning, rely on aligning your view to the superview's leading, trailing, top, or bottom edges.

有关大小,尝试设置你的看法有相同的高度或宽度与上海华。并根据需要调整乘数。

For sizing, try setting your view to have equal heights or widths with the superview. And adjusting the multiplier as needed.

这解决了汽车布局不一致,我在今天的Widget体验

This solved auto layout inconsistencies I was experiencing in a Today Widget.

更新瓦特/截图:

在这里输入的形象描述

见上面,我使用的对齐菜单(不可以 PIN菜单)。我选择这两个我试图约束观点,与全包围沿着上海华和(或用对齐)尾随边和底边告诉之前的佳品。

See above, I am using the align menu (not the pin menu). I select both the view I am trying to constrain, along with the all encasing superview, and tell the prior to share (or, align with) trailing and bottom edges.

我知道这是不是苹果公司会如何表现出它,但是它是不使用具有窗口小部件今日销时出现的错误一种解决方法。

I know this is not how Apple may demonstrate it, however it is a workaround that avoids the bugs that occur when using pins with Today Widgets.

更新#2 - 这里是所有的约束条件(包括高度和宽度):

Update #2 - And here is all the constraints (including height and width):

在这里输入的形象描述

该漏洞必须与被完全固定的,因为当我把我的观点的高度和宽度是相对于它的父视图的推断尺寸(而不是它可以推断​​),错误不发生。

The bug must be related to the inferred sizing of a view that is entirely pinned, because when I set the height and width of my view to be relative to its superview (rather than having it be inferred), the bug does not occur.

这篇关于今天不一致的Widget行为打破了子视图的身高限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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