2012-11-04 40 views
-1

我希望能夠在我創建的遊戲應用程序中打開相機。遊戲應用程序是使用iOS Objective C和HTML構建的。我想知道在本機端使用哪些函數,以及我在HTML和JS端使用的其他函數?在iOS應用程序中使用什麼功能或方法打開相機?

我知道我必須使用UIImagePickerController,我不完全明白,可能有人幫助?

+0

當你說HTML時,你的意思是PhoneGap或類似的東西?我認爲這些框架對於相機有自己的方法。 – pbaris

+0

不,我沒有使用phonegap或科爾多瓦,我試圖建立它沒有或。我試圖在本機上橋接HTML和iOS的本地代碼。 – user1798855

回答

1

在iPad上,您必須使用UIImagePickerController對象和委託和UIPopoverController來顯示彈出窗口中的選取器。來自我的應用程序的一些代碼。我用它從圖書館或相機加載圖像。

- (IBAction)choosePhoto:(id)sender { 

UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
picker.delegate = self; 

if ([sender tag] == FROM_LIBRARY) { 
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { 
     picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    } 
    else { 
     picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; 
    } 
} 
else if ([sender tag] == FROM_CAMERA) { 
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 
     picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
    } 
    else { 
     picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; 
    } 
} 

pop = [[UIPopoverController alloc] initWithContentViewController:picker]; 
pop.delegate = self; 
[pop presentPopoverFromRect:CGRectMake(234, 372, 300, 300) inView:self.view permittedArrowDirections:0 animated:YES]; 

[self hideMenu]; 
} 

則必須使用UIImagePickerControllerDelegate方法-(void)imagePickerController:(UIImagePickerController *)pk didFinishPickingMediaWithInfo:(NSDictionary *)info獲取圖像。

All are here http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html

+0

謝謝Szulc先生,對於iPhone來說會是一樣嗎? – user1798855

+0

不,在iphone上不使用'UIPopoverController'。 '[self presentModalViewController:picker animated:YES];'。你必須使用協議''。 –

+0

謝謝你在上面的代碼中曾經見過UIPopoverController,我用UIImagePickerControllerDelegate,UINaigationControllerDelegate替換它>非常感謝你! – user1798855

相關問題