【发布时间】:2015-10-10 08:49:24
【问题描述】:
我有一个正在运行的功能,但我不明白它为什么会起作用。我只是简单地使用这些值,直到它达到我想要的为止。我要求解释,因为我担心如果我不理解它的工作原理,它可能会在某些时候以不可预测的方式运行。
代码在用户长按按钮时运行。然后,代码将具有 30 个前导空格和 30 个尾随空格的图像放大到超级视图,使其没有前导空格和尾随空格。因为图片已经有了比例约束,所以要增加高度来保持图片的宽高比。
我不明白的是为什么我只需要从每个约束中减去 9 就可以让它近似地拥抱超级视图边缘,但我必须每个添加 30 才能让它恢复到原始大小。
//LONG PRESS FUNCTION
//Scoring Page: Fact Section
var zoomState = ""
@IBOutlet var fctBx_Img_LeadingCon: NSLayoutConstraint!
@IBOutlet var fctBx_Img_TrailCon: NSLayoutConstraint!
@IBAction func longPress(sender: UILongPressGestureRecognizer) {
if sender.state == UIGestureRecognizerState.Began {
if zoomState == "" {
fctBx_Img_TrailCon.constant = -9
fctBx_Img_LeadingCon.constant = -9
zoomState = "zoomed"
}
else {
fctBx_Img_TrailCon.constant = +30
fctBx_Img_LeadingCon.constant = +30
zoomState = ""
}
}
}
详情: 使用 Xcode 6.4 使用斯威夫特 使用故事板 使用自动布局,仅限 iPhone,仅限纵向 我是编程和应用开发新手。
【问题讨论】:
标签: swift layout autolayout nslayoutconstraint