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];

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

    记录下。

  • 相关阅读:
    【日语】标日初级上册单词(5-8)1
    【日语】标日初级上册单词(1-4)1
    【日语】计算机日语
    百家姓日语
    【日语】动物名称日语单词集合
    【日语】日语常用会话1000句
    【日语】编程相关日语词汇
    【日语】日语N5学习
    【日语】日语新闻核心词汇
    使用uni-app开发微信小程序之登录模块
  • 原文地址:https://www.cnblogs.com/try-wyh/p/4625192.html
Copyright © 2011-2022 走看看