简体   繁体   English

如何隐藏具有纵横比自动布局约束的UIImageView?

[英]How to hide an UIImageView with Aspect Ratio autolayout constraint?

I have a custom UITableViewCell where I have an image at the top with an Aspect Ratio constraint, and labels under my image with constraints relative to my image. 我有一个自定义UITableViewCell,其中在顶部的图像具有高宽比约束,在图像下方的标签具有相对于图像的约束。

I wan't to be able to hide my image so all the labels under are moved to the top where my image is. 我将无法隐藏我的图像,因此下面的所有标签都移到了我的图像所在的顶部。

With a fixed height constraint, I could create an IBOutlet and set the constant to 0, and it would work, but with an Aspect Ratio constraint, I don't know how to achieve this. 在固定的高度限制下,我可以创建一个IBOutlet并将常量设置为0,并且可以工作,但是在长宽比限制下,我不知道该如何实现。

Thanks! 谢谢!

The only solution that I see here is - when you need to hide it, than you should: 我在这里看到的唯一解决方案是-当您需要隐藏它时,您应该:

1) Get width of you view 2) set aspect ratio constraint active = NO 3) create width constraint from value getted before 4) create height constraint with constant = 0 5) add this two constraints(if doing from code) 6) Animate 1)获取视图的宽度2)设置宽高比约束为有效= NO 3)从之前获取的值创建宽度约束4)创建常量= 0的高度约束5)将这两个约束相加(如果从代码中进行)6)动画

As well you can create width and height constraints in builder with aspect ratio constraint and just manipulate with property active 同样,您可以使用宽高比约束在构建器中创建宽度和高度约束,并且只需在active属性的情况下进行操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM