为什么UIButton出现在UIView中,但起源是在视野之外?

时间:2015-02-10 21:52:09

标签: ios nslayoutconstraint

我在Xcode 6 Beta 5 / iOS 8项目中设置了一个视图控制器(在iPhone 6 Plus模拟器上运行)。视图控制器在Interface Builder故事板中放置并约束了以下子视图,其中包含AutoLayout约束:

  • 表格视图
  • 搜索字段
  • 分段控制
  • UIButton位于分段视图右侧的位置,约束它从superview尾随边缘(7点)插入。

视图控制器的视图框大小为(414,736)( iPhone 6 Plus 的尺寸)。但是,当我打印上面提到的插入UIButton的帧时,它显示origin.x = 545.这是方式在屏幕右边缘(414)的纵向方向上。然而,按钮在屏幕上设计的布局位置正确显示在分段控件的右侧。

如果我尝试在按钮上放置另一个视图,在x = 545时,覆盖的视图是不可见的(因为它离开了正确的屏幕,因为我预计UIButton也应该是这样)。并且我将重叠组件的X坐标值减少到理智的origin.x位置350左右,它出现在按钮的顶部。

为什么UIButton的框架与按钮的可见位置不匹配?我打印了视图控制器视图的所有约束(如下所示),但我没有看到任何可以解释其中的差异的内容。

发生了什么事?

<NSLayoutConstraint:0x7ff25c509230 UISearchBar:0x7ff259cecf50.trailing == UIView:0x7ff25c5083d0.trailingMargin>
<NSLayoutConstraint:0x7ff25c509280 UISearchBar:0x7ff259cecf50.leading == UIView:0x7ff25c5083d0.leadingMargin>
<NSLayoutConstraint:0x7ff25c5092d0 V:[_UILayoutGuide:0x7ff25c5084c0]-(0)-[UISearchBar:0x7ff259cecf50]>
<NSLayoutConstraint:0x7ff25c509320 UISegmentedControl:0x7ff259ce2960.trailing == UIButton:0x7ff259cde7f0.leading - 15>
<NSLayoutConstraint:0x7ff25c509370 UISegmentedControl:0x7ff259ce2960.leading == UITableView:0x7ff25a08f800.leading + 8>
<NSLayoutConstraint:0x7ff25c5093c0 V:[UISearchBar:0x7ff259cecf50]-(0)-[UISegmentedControl:0x7ff259ce2960]>
<NSLayoutConstraint:0x7ff25c509410 UITableView:0x7ff25a08f800.bottom == UIView:0x7ff25c5083d0.bottomMargin - 44>
<NSLayoutConstraint:0x7ff25c509460 V:[UISegmentedControl:0x7ff259ce2960]-(10)-[UITableView:0x7ff25a08f800]>
<NSLayoutConstraint:0x7ff25c5094b0 UITableView:0x7ff25a08f800.leading == UIView:0x7ff25c5083d0.leadingMargin>
<NSLayoutConstraint:0x7ff25c509500 UITableView:0x7ff25a08f800.trailing == UIView:0x7ff25c5083d0.trailingMargin>
<NSLayoutConstraint:0x7ff25c509550 UIButton:0x7ff259cde7f0.centerY == UISegmentedControl:0x7ff259ce2960.centerY>
<NSLayoutConstraint:0x7ff25c5095a0 UIButton:0x7ff259cde7f0.trailing == UIView:0x7ff25c5083d0.trailingMargin - 7>
<_UILayoutSupportConstraint:0x7ff259cf15d0 V:[_UILayoutGuide:0x7ff25c5084c0(0)]>
<_UILayoutSupportConstraint:0x7ff259cf1570 V:|-(0)-[_UILayoutGuide:0x7ff25c5084c0]   (Names: '|':UIView:0x7ff25c5083d0 )>
<_UILayoutSupportConstraint:0x7ff259cf2550 V:[_UILayoutGuide:0x7ff25c5087d0(0)]>
<_UILayoutSupportConstraint:0x7ff259cf24f0 _UILayoutGuide:0x7ff25c5087d0.bottom == UIView:0x7ff25c5083d0.bottom>

[ (0, 0), (414, 736) ] view.frame
pos:  (561, 122) clipboardButton.center
[ (0, 0), (414, 736) ] view.bounds
[ (545, 106), (32, 32) ] button.frame
[ (0, 0), (32, 32) ] button.bounds

0 个答案:

没有答案