当使用带有自定义相机控件的UIImagePickerController时,如何在音量增大事件上拍照? [英] How to take a photo on the volume-up event when using UIImagePickerController with custom camera controls?

查看:288
本文介绍了当使用带有自定义相机控件的UIImagePickerController时,如何在音量增大事件上拍照?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 5中,音量增大按钮现在可以在相机应用中拍摄照片,并在 UIImagePickerController 实例中,其中 .showsCameraControlls = =是。快乐的日子。

In iOS 5, the volume-up button will now take a photo in the camera app, and on a UIImagePickerController instance where .showsCameraControlls == YES. Happy days.

然而,当我将 showsCameraControlls 设置为,并提供我自己的(反过来触发 takePicture 方法),音量增大按钮将不再起作用。如何在UIImagePickerController显示时检测音量事件?

However, when I set showsCameraControlls to NO, and supply my own (which in turn triggers takePicture method), the volume-up button will no longer work. How can I detect the volume event while the UIImagePickerController is showing?

检测音量变化的旧方法如下:

The old way to detect volume changes was like so:

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

我将此代码添加到我的应用程序委托中。奇怪的是 volumeChanged:直到我第一次显示 UIImagePickerController 之后才会触发。更重要的是,它不会在UIImagePickerController可见时被触发(也不会显示通常的音量HUD),我想是因为Apple禁用它&劫持了这个事件。

I added this code to my application delegate. Strangely volumeChanged: is not triggered until after I show the UIImagePickerController for the first time. More importantly, it isn't triggered while the UIImagePickerController is visible (nor is the usual volume HUD shown), I guess since Apple disabled it & hijacked the event.

再一次,有没有办法检测音量增大按钮事件,而 UIImagePickerController

So once again, is there any way to detect the volume-up button event, while the UIImagePickerController is being displayed, when using custom camera controls, for the purpose of taking a photo?

如果您想知道为什么我需要使用自定义相机控件,它是因为我希望能够拍摄多张照片,标准相机控制不允许这些照片。

If you're wondering why I need to use custom camera controls, it is because I want the ability to take multiple photos, which the standard camera controls do not allow.

推荐答案

在iOS 8上你可以添加观察者到通知 _UIApplicationVolumeUpButtonDownNotification

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

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

如果您使用 UIImagePickerController ,我当时是能够捕获事件并使用它以自定义视图调用 TakePicture

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

除此之外, UIImagePickerController 确保按下音量增大不会改变音量。

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

我不确定Apple是否会批准应用程序听取通知;这似乎是最干净的方法。

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

这篇关于当使用带有自定义相机控件的UIImagePickerController时,如何在音量增大事件上拍照?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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