dispatch_after 的使用方法

                                             dispatch_after 的使用方法

1. dispatch 意思是:迅速执行

2. dispatch_after函数:

        void  dispatch_after ( dispatch_time_t  time, dispatch_queue_t  queue, dispatch_block_t  block );

          该方法的第一个参数是 time,第二个参数是 queue,第三个参数是要执行的 block。

3. dispatch_after 这个函数的作用是:

       在 time 时间后,把 block 任务添加到 queue 队列中 并不是表示在time时间后执行任务,
大部分情况该函数能达到我们的预期,只有在对时间要求非常精准的情况下才可能会出现问题。

4. dispatch_time_t有两种形式的构造方式(不能直接赋值):

                 第一种:相对时间    可以通过dispatch_time函数来获取,DISPATCH_TIME_NOW表示现在,NSEC_PER_SEC表示的是秒数,它还提供了NSEC_PER_MSEC表示毫秒

             第二种:绝对时间    可以通过dispatch_walltime函数来获取,dspatch_walltime需要使用timespec的结

构体来得到dispatch_time_t


5.代码展示:

    dispatch_after(        

          /**第一个参数time,通过dispatch_time函数来获取*/

          dispatch_time(DISPATCH_TIME_NOW, (int64_t)(self.imageView.animationDuration * NSEC_PER_SEC)),         

          /**第二个参数queue*/

          dispatch_get_main_queue(),         

          /**第三个参数block*/

          ^{

              self.timer = [NSTimerscheduledTimerWithTimeInterval:3.0 target:selfselector:@selector(timerAnimation)userInfo:nilrepeats:NO];

           }  

                  );




       
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
这个错误怎么解决:192.168.34.71 - - [14/Jan/2023 22:41:01] "GET /get_nb2_ip/ HTTP/1.1" 500 - Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2548, in __call__ return self.wsgi_app(environ, start_response) File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2528, in wsgi_app response = self.handle_exception(e) File "/usr/local/lib/python3.8/dist-packages/flask_cors/extension.py", line 165, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File "/usr/local/lib/python3.8/dist-packages/flask_cors/extension.py", line 165, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2525, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1823, in full_dispatch_request return self.finalize_request(rv) File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1842, in finalize_request response = self.make_response(rv) File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2170, in make_response raise TypeError( TypeError: The view function did not return a valid response. The return type must be a string, dict, list, tuple with headers or status, Response instance, or WSGI callable, but it was a Response.代码是这个:@app.route('/get_nb2_ip/') def get_nb2_ip(): #curl -i --basic -u admin:public -X GET "http://192.168.34.131:8081/api/v4/clients?_page=1&_limit=10" response = requests.get('http:192.168.34.131:8081/api/v4/clients?_page=1&_limit=10', auth=('admin', 'public')) return response
最新发布
02-06

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值