zoukankan      html  css  js  c++  java
  • 使用ReactiveCocoa为UIbutton增加长按功能,实现步进累加效果

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
    @weakify(btn)
    UILongPressGestureRecognizer *longPressGes = [[UILongPressGestureRecognizer alloc] init];
    [btn addGestureRecognizer:longPressGes];
    RACSignal *timer = [RACSignal interval:0.1 onScheduler:[RACScheduler mainThreadScheduler]];
    RACSignal *longPressGesSignal = [longPressGes rac_gestureSignal];
    RACSignal *longPressGesBeganSignal = [longPressGesSignal filter:^BOOL(UILongPressGestureRecognizer *value) {
        return value.state == UIGestureRecognizerStateBegan;
    }];
    RACSignal *longPressGesEndedSignal = [longPressGesSignal filter:^BOOL(UILongPressGestureRecognizer *value) {
        return value.state == UIGestureRecognizerStateEnded
        || value.state == UIGestureRecognizerStateCancelled
        || value.state == UIGestureRecognizerStateFailed ;
    }];
    RACSignal *notifyWhenNeed = [longPressGesBeganSignal flattenMap:^RACStream *(id value) {
        return [timer takeUntil:longPressGesEndedSignal];
    }];
    [notifyWhenNeed subscribeNext:^(id x) {
        @strongify(btn)
        [btn sendActionsForControlEvents:UIControlEventTouchUpInside];
    }];
    

      

  • 相关阅读:
    基于SAAJ的客户端
    SOAP消息的结构
    服务端的思考
    最简单的Web Service实现
    PLSQL的注释技巧
    复杂分支图示
    Tomcat常见错误
    maven常见错误
    SpringMvc参数传递中乱码问题
    springmvc常遇到的错误
  • 原文地址:https://www.cnblogs.com/ashamp/p/11397541.html
Copyright © 2011-2022 走看看