Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

IDMah

macrumors 6502
Original poster
May 13, 2011
317
11
Set up a UILongPressGestureRecognizer with:
Code:
       // set up LongPress //
	UILongPressGestureRecognizer *longPressRecognizer = 
	[[UILongPressGestureRecognizer alloc]
	 initWithTarget:self 
	 action:@selector(longPressDetected:)];
    longPressRecognizer.minimumPressDuration = 3;
    longPressRecognizer.numberOfTouchesRequired = 1;
    [self.window addGestureRecognizer:longPressRecognizer];
    [longPressRecognizer release];

and trigger an Alert with this.

Code:
-(void)longPressDetected:(UIGestureRecognizer *)recognizer {
	NSLog(@"Long Press");
	
	UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Really reset?" message:@"Do you really want to reset this game?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil] autorelease];
    // optional - add more buttons:
    [alert addButtonWithTitle:@"Yes"];
    [alert show];
}

but it seems to be triggering several Long Presses.. so showing more than one alert.. Can I clear the buffer some how .. or somehow do I Debounce this.. ???

thanks
Ian
 
Dude might be hacky but add a flag that is triggered when Alert is displayed
to stop more alerts. just remember to set it NO before..

Code:
-(void)longPressDetected:(UIGestureRecognizer *)recognizer {
	NSLog(@"Long Press");
	
	UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Really reset?" message:@"Do you really want to reset this game?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil] autorelease];
    // optional - add more buttons:
    [alert addButtonWithTitle:@"Yes"];
	
	if (alertShow==NO) {
		[alert show];
		}
	alertShow=YES;
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{

	NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
	if([title isEqualToString:@"Cancel"])
    {
        NSLog(@"Cancel");
		alertShow=NO;
	}
    else if([title isEqualToString:@"Yes"])
    {
        NSLog(@"Yes");
		alertShow=NO;
    }
    
}

Does anyone have a more elegant solution???
thanks.
Ian
 
Create an instance variable for an UIAlertView. Then check if it's visible via the UIAlertView.visible property. Not sure what you are trying to accomplish overall however are you sure adding a long gesture to window is ideal?

Good luck.
 
Maybe your long press detector isn't tolerant enough of motion?

I don't know what the behavior is if a touch strays too far... I'd think it would just cancel the gesture and the touch couldn't trigger the gesture again until the finger were lifted and pressed back down, but maybe not? Maybe if it strays outside it triggers a second long press?

That's my only guess right now.
 
tried but bounce

I tried using UIAlertView.visible but still bouncing.
The ugly hack seem to work..

also played with the movement setting on LongPress. but nothing.
I guess the correct way to to remove the longpress gesture once detected but that seem like more work than it's worth..

Shrug.. so for now.. I'll make due with ugly code.
but any other suggestions welcome.

thanks
Ian
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.