[英]changing constraints of a view
I have an Image view that is surrounded by 2 UIVIEWS which are the green top bar and blue side bar.我有一个被 2 个 UIVIEWS 包围的图像视图,它们是绿色的顶栏和蓝色的侧栏。
I have coded a tap gesture [FOR hiding the views], so If you tap once, the top and side bar hide and when tapped again, they re-appear.我编写了一个点击手势[用于隐藏视图],所以如果你点击一次,顶部和侧边栏会隐藏,再次点击时,它们会重新出现。
However, I want to code, that if the bars are visible, then the image view should hug itself to the bars and not extend, so as to prevent clipping.但是,我想编写代码,如果条形可见,则图像视图应将自身拥抱到条形而不延伸,以防止剪切。 Please see attached pic link请看附件图片链接
But when we tap and the bars go away, I want the image view to hug the super view, how can I do that?但是当我们点击和酒吧 go 离开时,我希望图像视图拥抱超级视图,我该怎么做?
I've coded the gesture like so:我已经像这样对手势进行了编码:
@IBAction func test(_ sender: UITapGestureRecognizer) {
print("single tap")
if top.isHidden == false && down.isHidden == false{
top.isHidden = true
down.isHidden = true
print("first")
} else{
top.isHidden = false
down.isHidden = false
}
You can try playing with anchor constraints.您可以尝试使用锚约束。
For example, put例如,放
imageView.topAnchor.constraint(equalto: topView.bottomAnchor).isActive = true
And same for side View so that they are always constraint to the image view edges.侧视图也是如此,因此它们始终受图像视图边缘的约束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.