首页 > ios如何判断用户停止点击按钮

ios如何判断用户停止点击按钮

用户连续点击同一个按钮,如何判断用户间断了3秒以上没有点击?


debounce(防抖)

# coffescript
debounce: (fn, context, wait)->
    tid = null
    # if content is a number, assign it to wait
    if not isNaN context
      wait = context if context > 0
      context = undefined
    wait = 200 if isNaN(wait) or wait < 0

    ->
      args = arguments
      clearTimeout tid
      tid = setTimeout ->
        fn?.apply context, args
        return
      , wait
      return

debounce(防抖)和throttle(节流)

以上为前端语法,参考原理


// 点击发送按钮

}

// 发送礼物时间间隔定时器 init

            // 发送本地消息
            if([weakSelf giftSendViewSendLocalMsg:gift]) {

                [weakSelf.waittingSendGifts addObject:gift];// 增加等待发送礼物
            }

            [weakSelf giftSendViewScheduledTimerDestroy];// 发送礼物时间间隔定时器 destroy
        }
    }];
}

}

// 发送多个礼物

        }

        // 把扣掉的余额加回来
        for (int i=0; i<sendFailGifts.count; i++) {

            DNGift *failureGift = [sendFailGifts objectAtIndex:i];
            weakSelf.giftSendView.remainMoney += failureGift.giftPrice.floatValue;// 减少余额
            NSLog(@"--------发送礼物[%@]失败!!!--------",failureGift.giftName);
        }
    } else {

        NSLog(@"--------发送礼物成功!!!--------");
    }

}];

// 清空等待发送的礼物
weakSelf.waittingSendGifts = [NSMutableArray arrayWithCapacity:0];

}


利用Objective-C的methodSwizzing,替换sendAction:to:forEvent:方法,在替换的方法里面定义一个变量用来存储点击的时间。
可以参考:
http://www.jianshu.com/p/e4f1...


你可以在点击按钮的时候开启一个定时器,判断时间间隔

【热门文章】
【热门文章】