tags:

views:

60

answers:

3

i m working on app,in which user taps to shoot bullets, i want user to restrict their taps, like he next tap or touch should be counted after 1 or 3 seconds,

is their any snippet,i can use to rtestrict user for continiously tapoping/touch?

quick reply is aleways appreciated/ regards shishir

A: 

Consider looking into the NSTimer class documentation.

Jasarien
+1  A: 

You can use NSTimer object like this.

Create flag in your class BOOL restrictTap;

Add this methods:

// is your tap method
- (void) tap {
    if ( restrictTap ) {
        return;
    }

    // do your staff

    restrictTap = YES;
    [NSTimer scheduledTimerWithTimeInterval:3 
                                     target:self 
                                   selector:@selector(enableTap)
                                   userInfo:nil 
                                    repeats:NO];
}

- (void) enableTap {
    restrictTap = NO;
}
Skie
I suggest that the code be modified to override `canBecomeFirstResponder` to check the value of `restrictTap``- (void) tap{ [self resignFirstResponder]; // Stops the view from receiving touch events restrictTap = YES; [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(enableTap) userInfo:nil repeats:NO];}- (void)enableTap{ restrictTap = NO;}- (BOOL)canBecomeFirstResponder{ return restrictTap ? NO : YES;}`
falconcreek
A: 

my code is something like this

if(bulletNo==-1) { bulletNo=6;

}

switch (bulletNo)

{
    case 6:
        [self.audioPlayer play ];
        bulletOne.hidden=FALSE;
        bulletTwo.hidden=FALSE;
        bulletThree.hidden=FALSE;
        bulletFour.hidden=FALSE;
        bulletFive.hidden=FALSE;
        bulletSix.hidden=FALSE; 
        break;


    case 5:
        [self.audioPlayer play ];
        bulletOne.hidden=FALSE;
        bulletTwo.hidden=FALSE;
        bulletThree.hidden=FALSE;
        bulletFour.hidden=FALSE;
        bulletFive.hidden=FALSE;
        bulletSix.hidden=TRUE;  
        break;

    case 4:
        [self.audioPlayer play ];
        bulletOne.hidden=FALSE;
        bulletTwo.hidden=FALSE;
        bulletThree.hidden=FALSE;
        bulletFour.hidden=FALSE;
        bulletFive.hidden=TRUE;
        bulletSix.hidden=TRUE;  

        break;

    case 3:
        [self.audioPlayer play ];
        bulletOne.hidden=FALSE;
        bulletTwo.hidden=FALSE;
        bulletThree.hidden=FALSE;
        bulletFour.hidden=TRUE;
        bulletFive.hidden=TRUE;
        bulletSix.hidden=TRUE;  

        break;

    case 2:
        [self.audioPlayer play ];

        bulletOne.hidden=FALSE;
        bulletTwo.hidden=FALSE;
        bulletThree.hidden=TRUE;
        bulletFour.hidden=TRUE;
        bulletFive.hidden=TRUE;
        bulletSix.hidden=TRUE;  

        break;

    case 1:
        [self.audioPlayer play ];
        bulletOne.hidden=FALSE;
        bulletTwo.hidden=TRUE;
        bulletThree.hidden=TRUE;
        bulletFour.hidden=TRUE;
        bulletFive.hidden=TRUE;
        bulletSix.hidden=TRUE;  



        break;

    case 0:
        [self.audioPlayer play ];
        bulletOne.hidden=TRUE;
        bulletTwo.hidden=TRUE;
        bulletThree.hidden=TRUE;
        bulletFour.hidden=TRUE;
        bulletFive.hidden=TRUE;
        bulletSix.hidden=TRUE;  

        reloadLabel.hidden=FALSE;

        [reloadbutton setHidden:NO];

        break;

    default:
        break;
}

on every tap,bullet value get decrement by one. i provided 6 bullet images,on each tap, bullet image gets visible and invidble,

now for ex if bullets ==60;

now,when the value of bulleNo becomes 0 ,on each 6th tap,all bullets gets invisible, so what i want is, wen all images gets invisble,i want to restrict user to tap. i already hv a shake function through which,when user shakes, all 6 images gets vissible.and wen all bullet images get visible,user start taps again...

hope m clear wat i want... quick reply is always appreciated... thanks anyways for replying dude.

shishir.bobby
it is not clear which view object is receiving the tap message. Which objects need to ignore tap messages?
falconcreek