How to take a photo on the volume-up event when using UIImagePickerController with custom camera controls?

我怕爱的太早我们不能终老 提交于 2019-11-29 08:47:53
Cristian Vyhmeister

On iOS 8 you can add an observer to the notification _UIApplicationVolumeUpButtonDownNotification

[[NSNotificationCenter defaultCenter] addObserver:self
                                      selector:@selector(volumeChanged:)
                                      name:@"_UIApplicationVolumeUpButtonDownNotification"
                                      object:nil];

If you are using UIImagePickerController, I was able to capture the event and use it to call TakePicture with a custom view.

On top of that, UIImagePickerController ensures that pressing volume up won't change the volume.

I'm not sure if Apple would approve an app listening to that notification; this seems to be the cleanest approach.

Try using the AVCapture APIs instead of UIImagePicker. Here's a tutorial:

http://www.musicalgeometry.com/?p=1273

It's a lot lower level and it's harder to use, but it shouldn't block the volume controls.

You might also want to try a trick like playing a silent audio file to enable the volume controls during image capture.

Update: I also found this tutorial on using the volume button for camera shutter:

http://ios.biomsoft.com/2011/12/07/taking-control-of-the-volume-buttons-on-ios-like-camera/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!