gpt4 book ai didi

ios - 检测 UIbuttons 是否重叠

转载 作者:行者123 更新时间:2023-11-28 18:21:48 25 4
gpt4 key购买 nike

我的 View 中有两个 UIButton,我正在尝试检测这两个是否重叠,以便执行以下操作:

如果(重叠)移动第二个按钮

我试过这个:

if (BluetoothDeviceButton.X1 < btn.X2 && BluetoothDeviceButton.X2 > btn.X1 &&
BluetoothDeviceButton.Y1 < btn.Y2 && BluetoothDeviceButton.Y2 > btn.Y1){

}

我真的无法得到我应该放什么而不是 X1、X2 等。而且我真的不知道这个方法是否会起作用。

最佳答案

CGRectIntersectsRect(CGRect rect1, CGRect rect2) 会告诉您它们的框架是否重叠。

if (CGRectIntersectsRect(btn.frame, BluetoothDeviceButton.frame)) {
...
}

关于ios - 检测 UIbuttons 是否重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19033460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com