I need some help. I need to integrate the camera into my app, and I want to learn about the following:
- I need the camera button on my view so that clicking it opens the camera view.
- I take a picture
- I need to code so that I have access to the Phone Gallery and then
display a pic in another view.
Could anyone please point me in the right direction?
Well,
UIImagePickerControlleris 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
UIBarButtonSystemItemCamerasystem item. This will give you the framework image.On tapping it, you will create a
UIImagePickerControllerinstance and present it modally.As you must’ve noticed that it has a
delegateproperty 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 inUIImagePickerControllerDelegateprotocol 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
UIImagePickerControllerinstance. However if you want to override their controls, you can do so by settingshowsCameraControlstoNOand 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 thetakePicturemethod. 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
mediaTypesproperty.