自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iPhone開發(fā)應(yīng)用中案例實現(xiàn)舉例

移動開發(fā) iOS
iPhone開發(fā)應(yīng)用中案例實現(xiàn)舉例是本文要介紹的內(nèi)容,主要是來學(xué)習(xí)以下小案例的實現(xiàn)過程,來看詳細內(nèi)容。

iPhone開發(fā)應(yīng)用中案例實現(xiàn)舉例是本文要介紹的內(nèi)容,主要是來學(xué)習(xí)以下小案例的實現(xiàn)過程,來看詳細內(nèi)容。

一、從 iPhone/iPad 圖片庫中讀取圖片的代碼

如果您的App涉及到從iPhone/iPad圖片庫讀取圖片,不妨看看CocoaChina版主“angellixf”分享的代碼,會為您節(jié)省很多時間。

  1. UIImagePickerController * picker = [[UIImagePickerController alloc] init];  
  2. picker.delegate = self;  
  3. picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;  
  4. [self presentModalViewController:picker animated:YES];  
  5.  
  6. UIImagePickerControllerSourceTypePhotoLibrary,// 相片庫  
  7. UIImagePickerControllerSourceTypeCamera//相機獲取圖片  
  8. UIImagePickerControllerSourceTypeSavedPhotosAlbum// 這個是自定義庫,是由用戶截圖或保存到里面的 

二、將圖片保存到相片庫的代碼:

  1. UIImageWriteToSavedPhotosAlbum(Image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); 

解析NSString形式xml的代碼

CocoaChina會員“marshluca”提出的問題:

  1. NSString *xmlString = @"<person><name>Jack</name><age>13< /age></person>"; 

如 何對這個xmlString構(gòu)造一個NSXML,以及如何解析構(gòu)造的NSXML.

解決方法:先轉(zhuǎn)換成NSData,然后用NSXMlParser進行解析。代碼:

  1. - (void)handleXMLData {       
  2.     NSString *myString = @"<addresses owner='swilson'><person><lastName>Doe</lastName><firstName>John</firstName></person></addresses>";   
  3.     NSData *myRequestData = [ NSData dataWithBytes: [myString UTF8String]  length:[myString length]];     
  4.     NSXMLParser *myParser = [[NSXMLParser alloc] initWithData:myRequestData];   
  5.     [myParser setDelegate:self];   
  6.     [myParser setShouldProcessNamespaces:YES];   
  7.     [myParser setShouldReportNamespacePrefixes:YES];   
  8.     [myParser setShouldResolveExternalEntities:NO];   
  9.     BOOL success = [myParser parse];   
  10.     [myParser release]; 

帖子地址 http://www.cocoachina.com/bbs/read.php?tid-20278.html

三、在iPhone播放背景音樂和按鍵生效的代碼

1、背景音樂播放    支持mp3格式 循環(huán)播放長音樂

這種播放音樂的方式導(dǎo)入框架#import <AVFoundation/AVFoundation.h>;

  1. NSString *musicFilePath = [[NSBundle mainBundle] pathForResource:@"changan" ofType:@"mp3"];       //創(chuàng)建音樂文件路徑  
  2.   NSURL *musicURL = [[NSURL alloc] initFileURLWithPath:musicFilePath];    
  3.  
  4.    AVAudioPlayer *thePlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:musicURL error:nil];  
  5.  
  6. // 創(chuàng)建播放器  
  7.   self.myBackMusic = thePlayer;    //賦值給自己定義的類變量  
  8.     
  9.   [musicURL release];  
  10.   [thePlayer release];  
  11.     
  12.   [myBackMusic prepareToPlay];  
  13.   [myBackMusic setVolume:1];   //設(shè)置音量大小  
  14.   myBackMusic.numberOfLoops = -1;//設(shè)置音樂播放次數(shù)  -1為一直循環(huán)  
  15.   if (mainMusicStatus)  
  16.   {  
  17.    [myBackMusic play];   //播放  
  18.   } 

2、按鈕播放聲音

需要導(dǎo)入框架#import <AudioToolbox/AudioToolbox.h> 

  1. NSString *thesoundFilePath = [[NSBundle mainBundle] pathForResource:@"Clapping Crowd Studio 01" ofType:@"caf"];    //創(chuàng)建音樂文件路徑  
  2. CFURLRef thesoundURL = (CFURLRef) [NSURL fileURLWithPath:thesoundFilePath];  
  3. AudioServicesCreateSystemSoundID(thesoundURL, &sameViewSoundID);  
  4.  
  5. //變量SoundID與URL對應(yīng)  
  6.  
  7. AudioServicesPlaySystemSound(sameViewSoundID);  // 播放SoundID聲音 

小結(jié):iPhone開發(fā)應(yīng)用中案例實現(xiàn)舉例的內(nèi)容介紹完了,希望通過本文的學(xué)習(xí)能對你有所幫助!

責(zé)任編輯:zhaolei 來源: starming社區(qū)
相關(guān)推薦

2011-08-15 15:44:46

iPhone開發(fā)PDF

2011-08-16 15:48:37

iPhone開發(fā)抓圖程序

2011-08-19 11:10:31

iPhone應(yīng)用

2011-08-19 10:13:05

iPhone開發(fā)

2011-08-18 15:24:40

iPhone國際化

2011-08-19 10:05:30

iPhone開發(fā)

2011-08-17 16:12:20

iPhone應(yīng)用程序

2011-08-18 16:42:07

iPhone應(yīng)用APNS推送

2011-08-15 11:23:41

iPhone開發(fā)循環(huán)滾動UIScrollVie

2011-08-15 18:02:32

iPhone開發(fā)表視圖

2011-08-10 17:37:00

iPhoneASIHTTPRequ

2011-08-16 15:36:47

iPhone應(yīng)用測試

2011-08-17 16:23:31

iPhone開發(fā)UIViewContr

2011-08-09 17:12:30

iPhoneCFRunLoop

2011-08-12 14:33:06

iPhone緩存文件

2011-08-22 14:12:48

iPhone開發(fā)NSTableView

2011-08-15 11:37:20

iPhone開發(fā)Mask

2011-08-19 10:01:09

iPhone應(yīng)用SqliteUITableView

2012-04-26 13:26:58

iPhone應(yīng)用技巧

2011-07-25 14:44:41

iPhone iPhone開發(fā) 截屏
點贊
收藏

51CTO技術(shù)棧公眾號