ViewController.m
代码:
#import "ViewController.h"
@interface ViewController ()
{
UIView *touchView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
touchView = [[UIView alloc] init];
touchView.backgroundColor = [UIColor brownColor];
touchView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height / 2 - [UIScreen mainScreen].bounds.size.height / 4, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height / 2);
[self.view addSubview:touchView];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressedOncell:)];
[touchView addGestureRecognizer:longPress];
longPress.allowableMovement = NO;
longPress.minimumPressDuration = 0.5;
}
-(void)longPressedOncell:(id)sender{
CGPoint p = [(UILongPressGestureRecognizer *)sender locationInView:touchView];
NSLog(@"press at %f, %f", p.x, p.y);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end