0

UIPanGestureRecogniserUIButtons 上使用。我想检测它们中的两个何时以下列方式重叠:

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...

基本上发生的是用户将 a拖到屏幕上一系列 s 中的UIButton任何其他上,这些 s 是 a 的一部分。当用户释放它们中的任何一个时,程序必须识别其中哪个重叠以及.UIButtonUIButtondictionarykeydictionary

我只能指定一个按钮,CGRectContainsPoint而且我也不知道如何理解它是哪一个按钮并keydictionary.

4

1 回答 1

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
    }
}
于 2013-09-14T17:59:19.747 回答