标签: nslayoutconstraint

UIScrollView中的UITableView使用autolayout

目前,我正在使用一个UITableView包含在其中的其他视图UIScrollView.我希望UITableView它的高度与其内容高度相同.

更复杂的是,我还插入/删除行以提供手风琴效果,这样当用户点击一行时,它将显示该行的更多细节.

我已完成插入/删除,但目前它没有更新UIScrollView,这是它的超级视图,以便UIScrollView重新计算内容大小,并且正确显示UITableView其中的其他视图UIScrollView.

我怎样才能实现这一点,以便UIScrollView在我更改内容时调整大小并正确布置其内容UITableView?我目前正在使用自动布局.

uitableview uiscrollview ios autolayout nslayoutconstraint

53
推荐指数
3
解决办法
4万
查看次数

UICollectionView自动调整高度

如何正确调整UICollectionView的大小以使其完全显示其内容?我尝试了很多东西,包括设置框架,调用reloadData和使布局无效:

self.collectionView.contentSize = CGSizeMake(300, 2000);
self.collectionView.frame = CGRectMake(0, 0, 300, 2000);
[self.collectionView reloadData];
[self.collectionView.collectionViewLayout invalidateLayout];
Run Code Online (Sandbox Code Playgroud)

但这些都没有任何影响.按下按钮后,我仍然看到初始视图,如下所示:

集合视图仅在帧大小调整后显示部分内容

我有一个小的演示程序,我有一个产生100个元素的数据源.在Interface Builder中,我最初将UICollectionView的大小设置为一个较小的值,以便不是所有元素都适合,之后我按下一个按钮,然后执行上面的代码.我希望UICollectionView现在显示所有元素,但事实并非如此.

编辑:演示程序可以在https://github.com/mjdemilliano/TestUICollectionView找到.

编辑2:我观察到帧更新在某些时候丢失,因为如果我再次按下按钮,当前帧将回到旧值.在按钮事件处理程序中添加一些日志语句后,日志输出为:

before: frame = {{0, 58}, {320, 331}}, contentSize = {320, 1190}
update button pressed
after: frame = {{0, 0}, {300, 2000}}, contentSize = {300, 2000}
before: frame = {{0, 58}, {320, 331}}, contentSize = {320, 1190}
update button pressed
after: frame = {{0, 0}, {300, 2000}}, contentSize = {300, 2000}
Run Code Online (Sandbox Code Playgroud)

我不明白为什么不保留框架更改,改变它的原因.

在某些时候,我将用流布局中获得的值替换硬编码值,但我想排除这一点,并尽可能简单地保持我的示例.

上下文:我最终想要做的是:我有一个可滚动的视图,包含标签和图像等各种控件,以及一个包含动态内容的集合视图.我想滚动所有这些,而不仅仅是集合视图,因此我没有使用集合视图自己的滚动工具,它工作正常.

objective-c ios uicollectionview nslayoutconstraint

50
推荐指数
2
解决办法
4万
查看次数

使用自动布局,如何根据图像使UIImageView的大小动态?

我希望我UIImageView的增长或缩小取决于它显示的实际图像的大小.但我希望它保持垂直居中,距离超视距的前沿10分钟.

但是,如果我设置这两个约束,它会抱怨我没有设置足够的约束来满足自动布局.对我来说,它似乎完美地描述了我想要的东西.我错过了什么?

objective-c uiimageview ios autolayout nslayoutconstraint

50
推荐指数
4
解决办法
5万
查看次数

以编程方式更新高度约束

我是汽车布局的新手.我已经完成了xib文件中的所有项目,但现在我遇到了一个问题,我必须以编程方式更新视图的高度.我试过下面但现在正在努力.

[[self view] addConstraint:[NSLayoutConstraint constraintWithItem:loginContainer attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:loginFrame.size.height]];
Run Code Online (Sandbox Code Playgroud)

在控制台中显示

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 …
Run Code Online (Sandbox Code Playgroud)

objective-c ios autolayout nslayoutconstraint swift

50
推荐指数
5
解决办法
6万
查看次数

AutoLayout可保持视图大小成比例

我正在努力实现以下目标:

  • 我的xib中有2个视图需要保持20个像素的边缘(两侧和顶部)
  • 需要调整大小的2个视图的大小不同
  • 它们必须相隔20个像素
  • 它们的宽度需要相对于父视图的宽度保持不变

我阅读了一个关于这样做的教程并且它可以工作,但问题是它需要两个视图具有相同的宽度和引脚Widths equally,这是我不想要的.

这是我试过的:

  • 将前导空间约束添加到左视图为20像素
  • 将顶部空间约束添加到左视图为20像素
  • 将顶部空间约束添加到右视图为20像素
  • 将尾部空间约束添加到右视图为20像素
  • 将水平间距约束添加到两个视图为20像素

我遇到的问题是左视图没有调整大小,右视图填充空间以保持20像素的水平空间.

有没有办法让两个视图按比例调整它们应该填充的空间?

以下是我的布局和约束的屏幕截图:

xib布局约束定义

谢谢!

编辑

我尝试旋转设备时收到以下警告:

2012-10-11 08:59:00.435 AutolayoutTest[35672:c07] 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 …
Run Code Online (Sandbox Code Playgroud)

interface-builder ios autolayout ios6 nslayoutconstraint

48
推荐指数
5
解决办法
6万
查看次数

Animate intrinsicContentSize更改

我有一个UIView子类绘制一个半径变化的圆(具有漂亮的弹性动画).视图决定了圆的大小.

我希望这个UIView子类更改其帧大小以匹配圆半径的动画更改,并且我希望这些更改可以修改连接到视图的任何NSLayoutConstraints(以便限制到圆的边缘的视图将移动为圈调整大小).

我理解半径更改时实现-(CGSize)intrinsicContentSize和调用invalidateIntrinsicContentSize将告诉约束更新,但我无法弄清楚如何动画更改intrinsicContentSize.

invalidateIntrinsicContentSize从[UIView animateWith ...块]中调用只是立即更新布局.

这是否可能,是否有解决方法/更好的方法?

cocoa-touch uiview nslayoutconstraint

48
推荐指数
2
解决办法
1万
查看次数

什么是'UIView-Encapsulated-Layout-Width'约束?

我一直得到'无法同时满足约束'的例外(Xcode 5,iOS 7,设备和模拟器),其中列表中的一个约束是这样的:

"<NSLayoutConstraint:0x165b23d0 'UIView-Encapsulated-Layout-Width'
H:[StoryPlayerCell:0x165affc0(0)]>"
Run Code Online (Sandbox Code Playgroud)

我自己没有设置这个约束.它也不是NSAutoresizingMaskLayoutConstraint.但是它来自哪里?我怎么能摆脱它呢?

我不知道.我'UIView-Encapsulated-Layout-Width'在Apple的文档中找不到任何相关内容.即便是谷歌搜索也没有任何回报.

有什么建议?

PS:我在UICollectionView一个自定义子类中使用这个单元格UICollectionViewFlowLayout.也许这'Encapsulated-Layout'部分与此有关?

ios autolayout uicollectionview nslayoutconstraint uicollectionviewlayout

48
推荐指数
2
解决办法
1万
查看次数

设备旋转时iOS更改自动布局约束

我想在设备旋转时修改布局约束.我UIViewController的由2个组成UIViews,在横向上它们是水平对齐的,在纵向上它们是垂直对齐的.

它实际上工作,在willAnimateRotationToInterfaceOrientation,我删除所需的约束,并将其替换为其他人,以获得正确的布局...

但是有一些问题,在旋转期间自动布局在willAnimateRotationToInterfaceOrientation调用之前开始打破约束,那么当设备重新定向发生时,我们在哪里更换我们的约束?

另一个问题是性能,在几次旋转之后系统不再破坏约束,但是我的性能下降很大,特别是在纵向模式下......

objective-c ios autolayout nslayoutconstraint

45
推荐指数
2
解决办法
4万
查看次数

什么是_UITemporaryLayoutWidth,为什么它会破坏我的约束?

我有一个包含Autolayout和Size Classes的故事板.相当复杂的布局,不幸的是我无法确定如何在新项目中重现问题.
但是有问题的视图被固定到屏幕的左边缘和右边缘,其约束具有750优先级(即|-(0@750)-[myView]-(0@750)-|,另外它具有大于或等于约束的优先级为1000(即|-(>=0)-[myView]-(>=0)-|).这样做是为了限制在iPad上的宽度,所以在容器约束中存在宽度约束width <= 600 @1000中心水平.最重要的是,视图的宽高比约束为3:1.正如我所说,相当复杂.

Interface Builder不会显示约束的任何问题.Xcode布局预览为所有设备呈现正确.

当我运行应用程序iOS时告诉我它有相互冲突的约束.

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 …
Run Code Online (Sandbox Code Playgroud)

ios autolayout nslayoutconstraint

43
推荐指数
6
解决办法
7388
查看次数

在Swift中以编程方式更新约束的常量属性?

我想动画一个对象,所以我声明一个约束并将其添加到视图中.然后我更新动画constant内约束的属性UIView.为什么这段代码没有移动对象?

UIView.animateWithDuration(1, animations: {
     myConstraint.constant = 0   
     self.view.updateConstraints(myConstraint)
})
Run Code Online (Sandbox Code Playgroud)

ios nslayoutconstraint swift

37
推荐指数
1
解决办法
5万
查看次数