How to make UIButton work like Launcher in SpringBoard, when pressed for long timeinterval

Posted by KayKay on Stack Overflow See other posts from Stack Overflow or by KayKay
Published on 2010-06-03T12:20:59Z Indexed on 2010/06/03 12:24 UTC
Read the original article Hit count: 346

In my ViewController I am using UIButton which triggers some action when touchedUpInside. Upto here no problem, but i also want to add another action for touchDown event. More precisely i dont have an idea how to add that action to which event, that will work the same as when App-Icon is pressed longer in springboard which causes springboard enter in editing mode.Actually what i want is : when this button is kept holding for ,say about 2 seconds it will pop-up an alertView without touch being heldUp (with finger is still on button).

I have tried with 2 NSdate difference, one of which is allocated when touchedDown and other when touchUpInside. Its working and popping alert,but only after touchedUpInside. I want it to show alert without touch being removed. Here is the code.

(IBAction)touchedDown:(id)sender {
momentTouchedDown = [[NSDate alloc] init];//class variable
NSLog(@"touched down");
}
- (IBAction)touchUpInside:(id)sender {
NSLog(@"touch lifted Up\n");    
NSDate *momentLifted = [[NSDate alloc] init];
double timeInterval = [momentLifted timeIntervalSinceDate:momentTouchedDown];
NSLog(@"time lifted = %@, time down = %@, time diff = %@", momentLifted, momentTouchedDown, [NSString stringWithFormat:@"%g",timeInterval]);
[momentLifted release];
   if(timeInterval > 2.0) {
            NSLog(@"AlertBox has been fired");
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Yes"
                                  message:@""//msg
                                  delegate:self
                                  cancelButtonTitle:@"Cancel"
                                  otherButtonTitles:@"OK"
                                  , nil];   
            [alert show];
            [alert release];
    }
}

Please provide me an insight..thanks for help in advance.

© Stack Overflow or respective owner

Related posts about uibutton

Related posts about nsdate