ios开发笔记之手势触控

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.");
    }
}

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。