iOS Interface Builder(XCode):将元素粘贴在一起

时间:2017-05-04 12:33:39

标签: ios xcode interface-builder constraints xcode8

我在XCode 8中遇到自动布局/约束问题。

以下是我的两个元素的截图:

enter image description here

头部是图像,虚线圆圈是按钮。我需要将按钮“粘贴”到背景图像上的这个特定位置,但约束不会对我这样做,因为它们总是与较大的布局元素相关,例如查看或顶部布局指南。

是否有可能将元素粘在一起,以便按钮将保持在特定位置(相对于背景中人物的图像)?

1 个答案:

答案 0 :(得分:0)

使用手势,不使用按钮

@IBOutlet var profileImageView: UIImageView!

在viewDidLoad

    let tabGesture = UITapGestureRecognizer(target: self, action: #selector(self.imageTapped))
    profileImageView.isUserInteractionEnabled = true
    profileImageView.addGestureRecognizer(tabGesture)

和你的功能

func imageTapped() {
    print("image tapped")
}