开发者

how to detect button pressed and released in iphone

how to detect a button is pressed and released because i want to perform two actions

first is auto increment when a button is pressed and hold a... and to stop the auto increment when a button is released .......

please tell me what button actions are to be used to do this ....

i tried with touchup inside touch down touch up out side but it is not working correctluy can any one please 开发者_运维技巧help me how to make it working correctly.....

thank you.


Ok, first you need an interface button. The Button's target action for Touch Down should trigger an action like this:

    if (someTimer == nil) {
    someTime = [NSTimer scheduledTimerWithTimeInterval:.03 target:self selector:@selector(theDecreasingMethod) userInfo:nil repeats:YES];
}

Then you need another IBAction set to that same button (YES you can set multiple actions to one button) and link that action to Touch Up Inside Then in the method associated with the touch up inside action:

if (someTimer != nil) {
    [someTimer invalidate];
    someTimer = nil;
}

Finally, in theDecreasingMethod, you need this

-(void)theDecreasingMethod{
//do what ever you need to incrementally do
//ie. someInt--;
}

I hope this helps; comment if you need anything else

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜