问题描述
我在左侧UIImageView
和右侧UIView
的单元格中都有两个视图,其中还包含其他一些视图,如图所示
I have two views in the cell at the left UIImageView
and at the right UIView
Containing some other views as in picture
现在我想要如果Cell的宽度为=> 300,那么View2
应该位于屏幕的右侧,如图片所示,否则应移至View1
的底部
Now I want if the width of Cell is => 300 then View2
should be at the right of Screen as it is in picture other wise it should be moved to the bottom of View1
推荐答案
做一件事.为该视图设置其他约束
Do one thing. Set another constraints for that view
1)进入主视图
2)从顶部到图像视图(您可以通过从视图上单击鼠标右键以拖动图像视图然后垂直间距来赋予此约束.)
2) top to imageview (you can give this constraint by right click from view to drag imageview then vertical spacing.)
现在以编程方式为这两个约束提供出口.
Now give outlets for this two constraints programatically.
并给出约束的出口:1)从视图到图像视图2)顶部.
And also give outlets for constraints which are:1) leading from view to imageview2) top of view.
现在根据您的要求设置条件
Now as per your requirement,set if condition
例如
if(width => 300)
{
topOfViewToImageviewConstraint.isActive = false
leadingOfViewToMainViewConstraint.isActive = false
}
else
{
leadingOfViewToImageViewConstraint.isActive = false
topOfviewToMainView.isActive = false
leadingOfViewToMainViewConstraint.constant = 0
topOfViewToImageviewConstraint.constant = 20
}
这篇关于自动布局如何将view2从右移到底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!