iOS 捕获长按事件,跟踪滑动轨迹

来源:互联网 发布:windows教育版 编辑:程序博客网 时间:2024/05/16 12:31

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
0 0
原创粉丝点击