我在UIPanGestureRecogniser
上使用UIButton
。我想通过以下方式检测其中两个重叠:
if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded ||
[(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateCancelled ||
[(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateFailed) {
CGPoint fingerPoint;
for(id key in BluetoothDeviceDictionary) {
UIButton* btn = [BluetoothDeviceDictionary objectForKey:key];
fingerPoint = [(UIPanGestureRecognizer*)sender locationInView:btn.superview];
}
//BLUETOOTH SHARING
if (CGRectContainsPoint(All buttons from dictionary.frame, fingerPoint)) {
for the UIButton that has been overlapped do...
基本上发生的是,用户将UIButton
拖放到屏幕上UIButton
的一系列UIButton
中的任何其他dictionary
。key
。当用户发布其中任何一个时,程序必须识别其中哪一个已重叠,并且dictionary
中的相对CGRectContainsPoint
。
我只能为key
指定一个按钮,我也不知道如何理解它是哪一个按钮,并从dictionary
获取{{1}}。
答案 0 :(得分:1)
尝试类似:
UIPanGestureRecognizer *gesture = (UIPanGestureRecognizer *)sender;
if(gesture.state == UIGestureRecognizerStateEnded ||
gesture.state == UIGestureRecognizerStateCancelled ||
gesture.state == UIGestureRecognizerStateFailed) {
CGPoint dropPoint = [gesture locationInView:gesture.view.superview];
for(id key in BluetoothDeviceDictionary) {
UIButton* btn = [BluetoothDeviceDictionary objectForKey:key];
if (CGRectContainsPoint(btw.frame, dropPoint)) {
// overlap - do something...
// maybe continue or return (if the loop shouldn't continue to test the other buttons
}
}