zoukankan      html  css  js  c++  java
  • IOS的一些小技巧

    1.播放短声音   

        SystemSoundID shake_sound_male_id = 0;
        NSString *thesoundFilePath = [[NSBundle mainBundle] pathForResource:@"ReceivedMessage" ofType:@"caf"]; //音乐文件路径
        CFURLRef thesoundURL = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:thesoundFilePath]);
        AudioServicesCreateSystemSoundID(thesoundURL, &shake_sound_male_id);
        AudioServicesPlaySystemSound(shake_sound_male_id);
        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);//播放震动

    2.播放系统声音

        AudioServicesPlaySystemSound(1004); //更换播放系统的声音 id值可以百度查询
        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);//震动

    3.在主线程中刷新UI

           dispatch_async(dispatch_get_main_queue(), ^{
               _lbName=@"Name";
            });

    4.函数延时执行

    //这样实现延时调用是错误的,playSound是不会被调用的 可以在主线程调用
    dispatch_async(dispatch_get_global_queue(2, 0), ^{
            [self performSelector:@selector(playSound) withObject:nil afterDelay:0.5f];//NSTimer 也需要注意这点
     });

    5.一个函数短时间多次触发,希望函数里摸个代码段只执行一次

    //这个是抄的 原地址http://www.cocoachina.com/bbs/read.php?tid=193276
    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(playSound) object:nil];
    [self performSelector:@selector(playSound) withObject:nil afterDelay:0.5f];

        以后要多记录一下咯,很短以为能记住,过段时间又忘了,又要打开以前的项目来看,自己记忆力真的不行,以后就多

    记录下。

  • 相关阅读:
    C# 获取类似java gettime() 的时间格式
    LUbuntu电脑棒安装指南
    Visual Studio Gallery
    SQL SERVER 分页存储过程
    asp.mvc获取checkbox、radio、select的值
    C#面向对象的一些笔记
    Javascript预解析、作用域、作用域链
    解决ajax请求cors跨域问题
    Asp.Net操作WebServices
    2019年科技趋势前10位
  • 原文地址:https://www.cnblogs.com/try-wyh/p/4625192.html
Copyright © 2011-2022 走看看