zoukankan      html  css  js  c++  java
  • NSTimer 实现时钟回调方法

    在开发过程中,发现时钟调用的地方比较多。所以对时钟进行了一个简单的统一封装。具体代码如下:

    1、时钟回调函数的声明:

    #pragma mark 时钟回调处理
    //时钟回调
    +(NSTimer*) lsScheduleTimerWithTimerInternal:(NSTimeInterval)interval
                                           block:(void(^)())block
                                         repeats:(BOOL)repeats;

    2、时钟回调函数的实现:

    /**
     *    @brief  时钟回调
     *    @param  paramete     请求参数
     *         interval:   时间间隔
     *          repeats:   重试次数
     *    @return     NSTimer
     */
    +(NSTimer*) lsScheduleTimerWithTimerInternal:(NSTimeInterval)interval
                                           block:(void(^)())block
                                         repeats:(BOOL)repeats
    {
        NSTimer* timer = [self scheduledTimerWithTimeInterval:interval
                                                       target:self
                                                     selector:@selector(lsTimerBlockInvoke:)
                                                     userInfo:[block copy]
                                                      repeats:repeats];
        [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
    
        //保留NSTimer类对象,可忽略
        return timer;
    }
    
    +(void)lsTimerBlockInvoke:(NSTimer*)timer
    {
        void(^block)() = timer.userInfo;
    
        if(block){
            block();
        }
    }
  • 相关阅读:
    leetcode[145]Binary Tree Postorder Traversal
    leetcode[146]LRU Cache
    leetcode[147]Insertion Sort List
    leetcode[148]Sort List
    Intro to WebGL with Three.js
    Demo: Camera and Video Control with HTML5
    js ar
    Jingwei Huang
    Tinghui Zhou
    MODS: Fast and Robust Method for Two-View Matching
  • 原文地址:https://www.cnblogs.com/xujinzhong/p/8465400.html
Copyright © 2011-2022 走看看