iPhone Xcode 相机集成教程 [英] iPhone Xcode Camera Integration Tutorials

查看:22
本文介绍了iPhone Xcode 相机集成教程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助.我需要将相机集成到我的应用中,并且我想了解以下内容:

I need some help. I need to integrate the camera into my app, and I want to learn about the following:

  1. 我需要视图上的相机按钮,以便单击它打开相机视图.
  2. 我拍照
  3. 我需要编写代码才能访问电话库,然后在另一个视图中显示图片.

谁能指点我正确的方向?

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];

您一定已经注意到它有一个 delegate 属性,该属性被定义为 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 然后实现您自己的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆