1.区分单击和双击事件
- (void)addTapHandler { // 单击的 Recognizer UITapGestureRecognizer* singleRecognizer; singleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapActon:)]; /** * 单击 */ singleRecognizer.numberOfTapsRequired = 1; // 单击 //给view添加一个手势监测; [self.feedView addGestureRecognizer:singleRecognizer]; // 双击的 Recognizer UITapGestureRecognizer* doubleRecognizer; doubleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapActon)]; /** * 双击 */ doubleRecognizer.numberOfTapsRequired = 2; //给view添加一个手势监测; [self.feedView addGestureRecognizer:doubleRecognizer]; [singleRecognizer requireGestureRecognizerToFail:doubleRecognizer]; }
2. UILongPressGestureRecognizer 执行两次的问题
- (void)handleLongPress:(UILongPressGestureRecognizer*)sender { if (sender.state == UIGestureRecognizerStateEnded) { NSLog(@"Long press Ended"); } else { NSLog(@"Long press detected."); } }
时间: 2024-10-29 19:10:09