Camera overlay disables rear camera button

You must Login before you can answer or comment on any questions.

I'm adding an overlay to the camera view, when doing so, the overlay adds on top of the whole view and makes it impossible to press the rear camera button and flash button on iPhone 4. Anyone got a solution?

4 Answers

if your overlay does not require user interaction, you could add touchEnabled:false to the overlay view itself, allowing the touch event to pass through to the buttons

You can always create your own camera switcher:

// create a button called 'camera_btn' 
 
// add it to your 'overlay' if the device has two cameras:
 
var cameras = Ti.Media.availableCameras;
for (var c=0;c<cameras.length;c++)
{
    // if we have a rear camera ... we add switch button
    if (cameras[c]==Ti.Media.CAMERA_REAR){
        overlay.add(camera_btn);
        break;
    }
}
then set up a click listener on it when needed to perform something like this (once the camera is opened)
function switchCameras(){
    if (Ti.Media.camera == Ti.Media.CAMERA_FRONT){
        Ti.Media.switchCamera(Ti.Media.CAMERA_REAR);
    } else {        
        Ti.Media.switchCamera(Ti.Media.CAMERA_FRONT);
    }
}

I have an iPhone 4 and an iPad 2... Whatever I do, the rear camera is always used.

Ti.Media.camera is always equal to Ti.Media.CAMERA_REAR Ti.Media.switchCamera(Ti.Media.CAMERA_FRONT) does nothing at all

I can switch cameras with the default buttons though... but I need to do it by code!

I'm using Titanium Mobile SDK 1.7.2

Thanks for your help...

I noticed that if you wanted to add an overlay and have custom buttons - then you cannot double tap on the live-camera view to focus on a particular area since Ti will block all the events going past your overlay.

Moreover, if you have allow editing enabled, the user cannot zoom and crop after the image is taken.

Everything that deals with the Camera in Ti is, unfortunately, very buggy.

Your Answer

Think you can help? Login to answer this question!