我今天遇到了这个奇怪的问题:
全新安装后,我的布局看起来不错;一个简单的视图,里面有一个按钮:
我使用的是xib而不是故事板(不是我的决定:(),而且它很简单:
但是,下次下拉通知中心时,视图会消失:
我在两种情况下都打印出了recursiveDescription和_autolayoutTrace,但看起来是一样的:
干净安装后:
var value = this.newTodo.trim();
发生错误时:
<UIView: 0x78ee8dc0; frame = (0 0; 272 0); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x78edeb20>>
| <XXXNormalButton: 0x78ef5a70; baseClass = UIButton; frame = (0 15; 130 32); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x78ee9da0>>
| | <UIImageView: 0x78e83330; frame = (0 0; 130 32); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x78e9f220>>
| | <UIButtonLabel: 0x7a13d660; frame = (39.5 6; 51.5 20); text = 'Button'; alpha = 0; opaque = NO; userInteractionEnabled = NO; animations = { opacity=<CABasicAnimation: 0x78e752e0>; }; layer = <_UILabelLayer: 0x7a13c150>>
_UIHostedWindow:0x78ef0d30
| UIView:0x7a1420d0
| | _NCWidgetViewControllerView:0x7a151390
| | | UIView:0x7a13f3c0
| | | | UIView:0x78ea1190
| | | | | •UIView:0x78ee8dc0
| | | | | | *XXXNormalButton:0x78ef5a70'Please activate...'
| | | | | | | UIImageView:0x78e83330
| | | | | | | UIButtonLabel:0x7a13d660'Button'
一个值得注意的细节:两种情况下的视图框架都是(0 0; 272 0),所以我甚至不确定它是否应该可见。
某些上下文:我从代码加载xib。如果我加载不同的xib,布局是正确的,所以我猜测可能会遗漏一些约束。
我尝试了什么:我尝试为我的按钮定义明确的顶部,高度和底部约束,在这种情况下,我在以下约束之间发生冲突:
<UIView: 0x78e84d00; frame = (0 0; 272 0); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x78e804e0>>
| <XXXNormalButton: 0x78e42eb0; baseClass = UIButton; frame = (0 15; 130 32); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x78e87ba0>>
| | <UIImageView: 0x78f5c140; frame = (0 0; 130 32); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x78f5b9d0>>
| | <UIButtonLabel: 0x78e97f60; frame = (39.5 6; 51.5 20); text = 'Button'; alpha = 0; opaque = NO; userInteractionEnabled = NO; animations = { opacity=<CABasicAnimation: 0x78f23d40>; }; layer = <_UILabelLayer: 0x78e87fb0>>
_UIHostedWindow:0x78f5fe50
| UIView:0x78f5e2a0
| | _NCWidgetViewControllerView:0x78e68bc0
| | | UIView:0x78e9b270
| | | | UIView:0x78e082b0
| | | | | •UIView:0x78e84d00
| | | | | | *XXXNormalButton:0x78e42eb0'Please activate...'
| | | | | | | UIImageView:0x78f5c140
| | | | | | | UIButtonLabel:0x78e97f60'Button'
如果我理解正确,(
"<NSLayoutConstraint:0x79f6f350 V:[XXXDefaultButton:0x79f6ea80'Please activate...']-(0)-| (Names: '|':UIView:0x79f6f1c0 )>",
"<NSLayoutConstraint:0x79f6f380 V:|-(10)-[XXXDefaultButton:0x79f6ea80'Please activate...'] (Names: '|':UIView:0x79f6f1c0 )>",
"<NSLayoutConstraint:0x79e46440 'UIView-Encapsulated-Layout-Height' V:[UIView:0x79f6f1c0(0)]>"
)
表示视图要自动调整高度为零。
我不明白为什么会这样。由于我被迫使用xibs,因此添加高度约束是不可能的(尽管我已经在属性检查器中设置了高度)。我完全陷入困境,任何帮助都会受到赞赏。