iPhone Xcode相机集成教程 [英] iPhone Xcode Camera Integration Tutorials
问题描述
我需要一些帮助。我需要将相机集成到我的应用程序,我想了解以下内容:
I need some help. I need to integrate the camera into my app, and I want to learn about the following:
- 我需要在我的视图上的相机按钮
- 我拍摄照片
- 我需要编码,以便我可以访问电话库,然后
在另一个视图中显示pic。
任何人都可以指出正确的方向吗?
Could anyone please point me in the right direction?
推荐答案
好了, UIImagePickerController
是您需要的工具。
Well, UIImagePickerController
is the tool you need. It will do most of the stuff in that checklist.
对于该按钮,您可以使用图形创建自定义按钮,或者如果您计划使用工具栏或导航栏来保存您的按钮,您可以使用 UIBarButtonSystemItemCamera
系统项目。
For the button you can create a custom button with graphics or if you are planning to use a tool bar or a navigation bar to hold your buttons, you can create the bar button using the UIBarButtonSystemItemCamera
system item. This will give you the framework image.
点击它时,您将创建一个 UIImagePickerController
实例并以模态呈现。
On tapping it, you will create a UIImagePickerController
instance and present it modally.
UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES];
[picker release];
您必须注意到它有一个委托
属性定义为 id< UIImagePickerControllerDelegate,UINavigationControllerDelegate> delegate;
所以你必须采用这两个协议,但在大多数情况下,你只实现两个方法 - imagePickerControllerDidCancel:
和 imagePickerController:didFinishPickingMediaWithInfo:
。在 UIImagePickerControllerDelegate
协议中有另一种方法,但已弃用。不要使用它,即使你看到它在这里提到很多。您期望取消处理程序写成这样,
As you must've noticed that it has a delegate
property which is defined as id < UIImagePickerControllerDelegate, UINavigationControllerDelegate> delegate;
so you will have to adopt both the protocols but in most cases you implement only two methods – imagePickerControllerDidCancel:
and imagePickerController:didFinishPickingMediaWithInfo:
. There is another method in UIImagePickerControllerDelegate
protocol but that's deprecated. Don't use it even if you see it mentioned a lot around here. You would expect the cancel handler to be written like this,
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissModalViewControllerAnimated:YES];
}
其他方法是你做大部分的东西。
The other methods is where you do most of the stuff.
- (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
code> cameraOverlayView 。如果你这样做了并且分配了一个按钮来拍摄照片,你实际上可以使用 takePicture
方法触发图片动作。因此,这应该解决#2
。
Taking the picture is done automatically by the UIImagePickerController
instance. However if you want to override their controls, you can do so by setting showsCameraControls
to NO
and then implementing your own cameraOverlayView
. If you've done so and have assigned a button to take the picture, you can actually trigger the picture action using the takePicture
method. So this should address #2
.
您可以使用其他属性来调整图像选择器。例如,您可以将用户限制为仅使用 mediaTypes
属性来拍摄图像。
You can use other properties to adjust your image picker too. For example, you can limit the user to only taking images using the mediaTypes
property.
这篇关于iPhone Xcode相机集成教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!