We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
好吧,
UIImagePickerController
是您需要的工具。它将完成该清单中的大部分内容。对于按钮,您可以创建带有图形的自定义按钮,或者如果您计划使用工具栏或导航栏来保存按钮,则可以使用
UIBarButtonSystemItemCamera
系统项。这将为您提供框架图像。点击它后,您将创建一个 UIImagePickerController 实例并以模态方式呈现它。
您一定已经注意到,它有一个
delegate
属性,定义为id
id
因此您必须采用这两种协议,但在大多数情况下您只实现两个方法 -delegate
。 UIImagePickerControllerDelegate、UINavigationControllerDelegate> delegate;imagePickerControllerDidCancel:
和imagePickerController:didFinishPickingMediaWithInfo:
。UIImagePickerControllerDelegate
协议中还有另一种方法,但已弃用。即使您看到这里多次提到它,也不要使用它。您可能希望取消处理程序像这样编写,其他方法是您执行大部分操作的地方。
拍照是由
UIImagePickerController
实例自动完成的。但是,如果您想覆盖它们的控件,可以通过将showsCameraControls
设置为NO
,然后实现您自己的cameraOverlayView
来实现。如果您已这样做并分配了一个按钮来拍照,则实际上可以使用takePicture
方法触发拍照操作。所以这应该解决#2
。您也可以使用其他属性来调整图像选择器。例如,您可以使用
mediaTypes
属性限制用户仅拍摄图像。Well,
UIImagePickerController
is the tool you need. It will do most of the stuff in that checklist.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.On tapping it, you will create a
UIImagePickerController
instance and present it modally.As you must've noticed that it has a
delegate
property which is defined asid < UIImagePickerControllerDelegate, UINavigationControllerDelegate> delegate;
so you will have to adopt both the protocols but in most cases you implement only two methods –imagePickerControllerDidCancel:
andimagePickerController:didFinishPickingMediaWithInfo:
. There is another method inUIImagePickerControllerDelegate
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,The other methods is where you do most of the stuff.
Taking the picture is done automatically by the
UIImagePickerController
instance. However if you want to override their controls, you can do so by settingshowsCameraControls
toNO
and then implementing your owncameraOverlayView
. If you've done so and have assigned a button to take the picture, you can actually trigger the picture action using thetakePicture
method. So this should address#2
.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.解释一下文档,从 iOS6 开始,
dismissModalViewControllerAnimated:
已被弃用。请改用dismissViewControllerAnimated:completion:
。Paraphrasing the docs,
dismissModalViewControllerAnimated:
is deprecated from iOS6 onwards. UsedismissViewControllerAnimated:completion:
instead.