saurav
saurav

Reputation: 11

uigesturerecognizer in iphone app

Hello I want to emulate a long a press button? how can I do this? I think a timer is needed. Can you help me? I see UILongPressGestureRecognizer but how can I utilize this type?

here is the code , it isn't recognize long press

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
[self.button addGestureRecognizer:longPress];
[longPress release];

- (void)longPress:(UILongPressGestureRecognizer*)gesture {
    if ( gesture.state == UIGestureRecognizerStateEnded ) {
         NSLog(@"Long Press");
    }
}

Upvotes: 1

Views: 668

Answers (1)

DHamrick
DHamrick

Reputation: 8488

In order to utilize UILongPressGestureRecognizer you must set the minimumPressDuration property. This specifies how long to wait until your gesture recognizer is fired. For example

UILongPressGestureRecognizer *longPress = [[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)] autorelease];
longPress.minimumPressDuration = 2.0f;
[self.button addGestureRecognizer:longPress];

- (void)longPress:(UILongPressGestureRecognizer*)gesture {
    if ( gesture.state == UIGestureRecognizerStateEnded ) {
         NSLog(@"Long Press");
    }
}

Upvotes: 2

Related Questions