我需要一些幫助。我需要將相機集成到我的應用程序中,並且我想了解以下內容:iPhone Xcode相機集成教程
- 我需要我的視圖上的相機按鈕,以便點擊它可以打開相機視圖。
- 我拍照
- 我需要編碼才能進入手機庫,然後 在另一個視圖中顯示圖片。
請問誰能指點我正確的方向?
我需要一些幫助。我需要將相機集成到我的應用程序中,並且我想了解以下內容:iPhone Xcode相機集成教程
請問誰能指點我正確的方向?
好,UIImagePickerController
是你需要的工具。它將完成該清單中的大部分內容。
對於按鈕,您可以使用圖形創建自定義按鈕,或者如果您打算使用工具欄或導航欄來按住按鈕,則可以使用UIBarButtonSystemItemCamera
系統項創建欄按鈕。這會給你框架圖像。
在點擊它時,您將創建一個UIImagePickerController
實例並以模態方式呈現它。
UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES];
[picker release];
正如你一定是注意到它被定義爲id < UIImagePickerControllerDelegate, UINavigationControllerDelegate> delegate;
所以你將不得不採取兩種協議,但在大多數情況下,你只實現兩種方法delegate
財產 - imagePickerControllerDidCancel:
和imagePickerController:didFinishPickingMediaWithInfo:
。 UIImagePickerControllerDelegate
協議中有另一種方法,但不推薦使用。即使你看到它在這裏提到很多,也不要使用它。你可能會認爲取消處理程序被寫成這樣,
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissModalViewControllerAnimated:YES];
}
其他方法是你做的大部分的東西。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage * image = [info objectForKey:UIImagePickerControllerEditedImage];
// You have the image. You can use this to present the image in the next view like you require in `#3`.
[self dismissModalViewControllerAnimated:YES];
}
拍照是由UIImagePickerController
實例自動完成的。但是,如果您想要覆蓋其控件,可以將showsCameraControls
設置爲NO
,然後執行您自己的cameraOverlayView
。如果你已經這樣做並且已經分配了一個按鈕來拍攝照片,你可以使用takePicture
方法實際觸發照片動作。所以這應該解決#2
。
您也可以使用其他屬性來調整圖像選擇器。例如,您可以限制用戶僅使用mediaTypes
屬性拍攝圖像。
解釋文檔,dismissModalViewControllerAnimated:
已從iOS6開始棄用。改爲使用dismissViewControllerAnimated:completion:
。
嗨訪問此鏈接http://stackoverflow.com/questions/10176020/how-to-take-picture-from-camera-using-iphone-app –