//长按手势 UILongPressGestureRecognizer * longPressGr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressToDo:)]; longPressGr.minimumPressDuration = 1.0; [self.view addGestureRecognizer:longPressGr];
</pre><pre code_snippet_id="539697" snippet_file_name="blog_20141202_4_5196992" name="code" class="objc">//长按
-(void)longPressToDo:(UILongPressGestureRecognizer *)gesture
{
if(gesture.state == UIGestureRecognizerStateBegan)
{
CGPoint pointkk = [gesture locationInView:self.view];
NSLog(@"长按,point%@",NSStringFromCGPoint(pointkk));
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@""
message:@"Do you want to save this mode?"
delegate:self
cancelButtonTitle:@"No"
otherButtonTitles:@"Yes", nil];
[alertView show];
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"按下的按钮 …%d",buttonIndex);
if (buttonIndex == 1) {
//保存数据到NSDefault
}
}