【问题标题】:Controlling drag move with tap count in iPhone在 iPhone 中通过点击计数控制拖动移动
【发布时间】:2011-11-03 19:05:47
【问题描述】:

我有一个自定义按钮类.. 我希望能够通过点击计数来控制这个按钮.. 当用户只点击一次时,按钮会弹出一个评论框。 当用户点击两次或点击一次并按住按钮超过 2 秒时,按钮将开始拖动。 我将这些行添加到我的自定义按钮类中以捕获拖动事件..

[self addTarget:self action:@selector(dragBegan:withEvent:) forControlEvents: UIControlEventTouchDown];
[self addTarget:self action:@selector(dragMoving:withEvent:) forControlEvents: UIControlEventTouchDragInside];
[self addTarget:self action:@selector(dragEnded:withEvent:) forControlEvents: UIControlEventTouchUpInside | UIControlEventTouchUpOutside];


-(void)dragBegan:(UIControl *)c withEvent:ev {
[delegate customDragBegan:c withEvent:ev];

我试过这个功能:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

};

但是当触摸结束时,dragEnds 不会触发..我有点搞砸了..

现在,我可以正确拖动按钮了.. 只需要弄清楚如何控制第一次尝试... 2 点击拖动,1 点击另一个功能..

提前谢谢你..

【问题讨论】:

    标签: iphone cocoa-touch touch drag


    【解决方案1】:

    我找到了解决方案:(有点新手,但它解决了我的问题)
    我使用触摸事件..当触摸开始时,我检查触摸计数..如果它等于 2,那么我调用我的委托自定义拖动功能..并将我的 isDraggable BOOL 设置为是..所以在触摸结束功能中我可以确定是否我应该在委托中调用自定义拖动结束函数..

    希望对像我这样的人有所帮助..

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    
    UITouch *touchSample = [[event allTouches] anyObject];
    switch ([touchSample tapCount]) {
        case 1:
            isDraggable = NO;
            NSLog(@"SHOW COMMENT");
            break;
        case 2:
            isDraggable = YES;
            NSLog(@"START DRAG");
            [delegate customDragBegan:self withEvent:event];
            break;   
        default:
    
            break;
    }
    
    
    };
    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    if (isDraggable) {
        [delegate customDragMoving:self withEvent:event];
    };
    
    
    };
    
    -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    
    if (isDraggable) {
        [delegate customDragEnded:self withEvent:event];
    };
    
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 2014-07-25
      • 1970-01-01
      相关资源
      最近更新 更多