开发者

How to find touches on button using timer

I have button event. If single tap(touch) on 开发者_运维技巧button i am doing Flip action . If Double tap on button i am doing another action that is unhidden other button. Both same button event.i tried in image touches but not getting. How to find single tap or double Tap on button . how to implement timer to find touches any sample or tutorial ..


This might get you started..

(i have used 0.5 for a timeout value, but you might want to change this)

    -(void)butonEvent:(id)sendr{


    if(buttonTimer)[self doublePress];
    else
    {

    //buttonTimer is a local NSTimer

    buttonTimer = [NSTimer scheduledTimerWithTimeInterval: 0.5
                     target: self
                     selector: @selector(handleTimer:)
                     userInfo: nil
                     repeats: NO];
    }

    }


    -(void)singlePress{
[buttonTimer invalidate];buttonTimer=nil;//edit
    NSLog(@"Single Press");
    }

    -(void)doublePress{
[buttonTimer invalidate];buttonTimer=nil;//edit
    NSLog(@"doublePress");
    }

    -(void)handleTimer:(id)sendr
    {        
    [self singlePress];
    }


There is two options in UIButton Events,

You can use the following to detect, single touch through TouchDown, double touch through TouchDownRepeat. You can connect ur UIButtons using IB same way as like TouchUpInside and write ur coding accoring to that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜