新聞中心

        iOS開發(fā)技巧匯總

        作者: 時(shí)間:2012-12-05 來(lái)源:網(wǎng)絡(luò) 收藏

         1、獲取全局的Delegate對(duì)象,這樣我們可以調(diào)用這個(gè)對(duì)象里的方法和變量:
          [(MyAppDelegate*)[[UIApplication sharedApplication] delegate] MyMethodOrMyVariable];
          2、獲得程序的主Bundle:
          NSBundle *bundle = [NSBundle mainBundle];
          Bundle可以理解成一種文件夾,其內(nèi)容遵循特定的框架。
          Main Bundle一種主要用途是使用程序中的資源文件,如圖片、聲音、plst文件等。
          NSURL *plistURL = [bundle URLForResource: @plistFile withExtension: @plist];
          上面的代碼獲得plistFile.plist文件的路徑。
          3、在程序中播放聲音:
          首先在程序添加AudioToolbox:
          其次,在有播放聲音方法的.m方法添加#import:
          #importAudioToolbox/AudioToolbox.h>
          接下來(lái),播放聲音的代碼如下:
          NSString *path = [[NSBundle mainBundle] pathForResource: @soundFileName ofType: @wav];
          SystemSoundID soundID;
          AudioServicesCreateSystemSoundID ((__bridge CFURLRef)[NSURL fileURLWithPath:path], soundID);
          AudioServicesPlaySystemSound (soundID);
          4、設(shè)置和獲取類中屬性值:
          [self setValue: 變量值 forKey: 變量名];
          [self valueForKey: 變量名];
          5、讓某一方法在未來(lái)某段時(shí)間之后執(zhí)行:
          [self performSelector: @selector(方法名) withObject:nil afterDelay:延遲時(shí)間(s)];
          6、獲得設(shè)備版本號(hào):
          float version = [[[UIDevice currentDevice] systemVersion] floatValue];
          7、捕捉程序關(guān)閉或者進(jìn)入后臺(tái)事件:
          UIApplication *app = [UIApplication sharedApplication];
          [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(applicationWillResignActive: ) name:UIApplicationWillResignActiveNotification object:app];
          applicationWillResignActive:這個(gè)方法中添加想要的操作
          8、查看設(shè)備支持的字體:
          for (NSString *family in [UIFont familyNames]) {
          NSLog(@%@, family);
          for (NSString *font in [UIFont fontNamesForFamilyName:family]) {
          NSLog(@t%@, font);
          }
          }
          9、為UIImageView添加單擊事件:
          imageView.userInteractionEnabled = YES;
          UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action: @selector(yourHandlingCode: (];
          [imageView addGestureRecognizer:singleTap];
          10、添加多語(yǔ)言支持: 比如Image Picker這樣的組件,它上面的按鈕的文字是隨著設(shè)備語(yǔ)言環(huán)境的改變而改變的,但是要先在工程添加語(yǔ)言:
          11、使程序支持iTunes這樣的設(shè)備,比如可以使用PC端的工具往程序的Documents中拖放文件。
          12、頁(yè)面切換效果設(shè)置:
          controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
          [self presentModalViewController:controller animated:YES];
          可供使用的效果:
          UIModalTransitionStyleCoverVertical
          UIModalTransitionStyleFlipHorizontal
          UIModalTransitionStyleCrossDissolve
          UIModalTransitionStylePartialCurl
          恢復(fù)之前的頁(yè)面:
          [self dismissModalViewControllerAnimated:YES];

        本文引用地址:http://www.104case.com/article/185542.htm


        關(guān)鍵詞: iOS 開發(fā)技巧

        評(píng)論


        相關(guān)推薦

        技術(shù)專區(qū)

        關(guān)閉
        主站蜘蛛池模板: 肃宁县| 博野县| 柳江县| 太保市| 广西| 宁乡县| 法库县| 当阳市| 金秀| 乡宁县| 响水县| 上高县| 高淳县| 金湖县| 彩票| 宁晋县| 贡嘎县| 三亚市| 沭阳县| 抚宁县| 织金县| 江陵县| 滦南县| 留坝县| 驻马店市| 益阳市| 吕梁市| 涪陵区| 涞源县| 蕲春县| 堆龙德庆县| 苍梧县| 黄骅市| 桓台县| 威远县| 滦南县| 辽阳县| 辽阳市| 无极县| 金平| 奎屯市|