iOS UIButton单双击处理响应不同的方法

Posted 助金

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS UIButton单双击处理响应不同的方法相关的知识,希望对你有一定的参考价值。

  //显示目标 双击显示当前用户坐标位置
   UIButton * btnShowDistination = [[UIButton alloc]initWithFrame:CGRectMake(15, SCREEN_HEIGHT-110-64, 35, 35)];
    [btnShowDistination setBackgroundImage:[UIImage imageNamed:@"show_distination"] forState:UIControlStateNormal];
    [btnShowDistination addTarget:self action:@selector(btnTouchOne:forEvent:) forControlEvents:UIControlEventTouchDown];
    
    [btnShowDistination addTarget:self action:@selector(buttonRepeatAction:) forControlEvents:UIControlEventTouchDownRepeat];

    [self.view addSubview:btnShowDistination];

    

}

- (void)btnTouchOne:(UIButton *)sender forEvent:(UIEvent *)event
{
    [self performSelector:@selector(showDistination:) withObject:sender afterDelay:0.3];
}

- (void)buttonRepeatAction:(UIButton *)sender{
    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showDistination:) object:sender];
    [self showsUserLocation:sender];
}

- (void)showsUserLocation:(UIButton *)sender
{
    if (_mapView.userLocation) {
        [_mapView setCenterCoordinate:_mapView.userLocation.coordinate animated:YES];
        _mapView.zoomLevel = 17;
    }
}

- (void)showDistination:(UIButton *)sender{
    
    if (_circle) {
    [_mapView setCenterCoordinate:_circle.coordinate animated:NO];
        _mapView.zoomLevel = 17;
    }
    
}

 

以上是关于iOS UIButton单双击处理响应不同的方法的主要内容,如果未能解决你的问题,请参考以下文章

单双击的冲突处理

iOS UIButton 点击无响应的解决办法

UIButton的使用

磁盘单双缓冲区时间计算题总结

iOS:UIButton touch up inside 不响应多次按下

iOS - UIButton 成为打开键盘的第一响应者