How can I load a view based on how long I hold a UIButton?
Posted
by Thomas
on Stack Overflow
See other posts from Stack Overflow
or by Thomas
Published on 2010-03-25T19:28:52Z
Indexed on
2010/03/25
19:33 UTC
Read the original article
Hit count: 366
Hello all,
I've searched the net and documentation, but haven't found anything quite like what I'm trying to do. I'm working on an app where I want to load one view if a UIButton is held for x seconds, another if it's held for x+y seconds, etc. I found this tutorial. The problem I'm running into is, how do I switch the length of the button press? The tutorial switched the number of taps.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSSet *allTouches = [event allTouches];
switch ([allTouches count])
{
case 1: // Single touch
{
// Get the first touch.
UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
switch ([touch tapCount])
{
case 1: // Single Tap.
{
// Start a timer
timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showAlertView:) userInfo:nil repeats:NO];
[timer retain];
}
break;
case 2: // Double tap.
break;
}
}
break;
case 2: // Double touch
{
}
break;
default:
break;
}
}
Any suggestions?
Thanks! Thomas
© Stack Overflow or respective owner