Auto Layout how to move the view2 from right to the bottom?

南楼画角 提交于 2019-12-24 07:39:52

问题


I have two views in the cell at the left UIImageView and at the right UIView Containing some other views as in picture

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


回答1:


Do one thing. Set another constraints for that view

1) leading to main view

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.

And also give outlets for constraints which are: 1) leading from view to imageview 2) top of view.

Now as per your requirement,set if condition

e.g.

if(width => 300)

{

topOfViewToImageviewConstraint.isActive = false

leadingOfViewToMainViewConstraint.isActive = false

}

else

{

leadingOfViewToImageViewConstraint.isActive = false

 topOfviewToMainView.isActive = false

 leadingOfViewToMainViewConstraint.constant = 0

 topOfViewToImageviewConstraint.constant = 20

}



回答2:


This will work. I am not currently in Xcode, so this is just some sample code, but the idea will work. in cellForRowAt check if self.tableView.cellForRowAt(IndexPath.row).frame.width => 300 if it is, make no change, but if it is not find the y coordinate of the bottom of view 1 and make a new rect at (x: 0, y: botOfView1, width, height). Then set the frame of view 2 equal to that.



来源:https://stackoverflow.com/questions/42329996/auto-layout-how-to-move-the-view2-from-right-to-the-bottom

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!