There are several apps on the app store that use the camera with a custom overlay, but also support default touch-to-focus behavior on a iPhone 3GS. This doesn’t seem supported directly through the APIs, but the PLPreviewView subview is the view that needs to get the touch events in order to continue supporting the tap-to-focus behavior. By default, once you add a overlay to the UIImagePickerController, the overlay gets all the touches and doesn’t pass the touches on to the PLPreviewView. In order to get around this behavior, we have to get the PLPreviewView subview and manually pass on the touchesBegan events.
I am not sure if you will have trouble getting this through the app store, so try at your own risk.
Create a custom UIView that has access a @property for the UIImagePickerController named picker.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UIView * previewView = [[[[[[[[[[ self.picker.view // UILayoutContainerView subviews] objectAtIndex:0] // UINavigationTransitionView subviews] objectAtIndex:0] // UIViewControllerWrapperView subviews] objectAtIndex:0] // UIView subviews] objectAtIndex:0] // PLCameraView subviews] objectAtIndex:0]; // PLPreviewView [previewView touchesBegan:touches withEvent:event]; }
I’ve been looking for this for a day! Thank you!
Only thing is that it doesn’t seem to work with OS 4. Should I expect to see the blue autofocus square where I tap?
No, the blue focus square is not automatically shown when you hide the default controls. As for iOS 4, they have added APIs to do this. If you look at the WWDC 10 session 409, the example code for AVCam has a good example of using the new APIs. The lines of interest are included below, but you will want to look at the actual code sample because it has some surrounding device locking code. I haven’t had a chance to experiment much with it myself.
AVCaptureDevice *device = [[self videoInput] device];
[device setFocusPointOfInterest:point];
I know that this is an old post, but I thought I should mention that ios 4.3 DOES show the blue focus square, even if you hide the default controls. I’m trying to find out how to hide it now. I was developing an augmented reality app, and the focus square is really distracting now. It wasn’t doing this before 4.3
AWESOME! Thank you so much for the pointers!
lol, pointers
Hi. i tried this code on iPhone4 iOS4.2
But, unfortunately this code doesn’t work.
if you can send to a sample code. im really happy.
i’m beginner Object-c Programmer.
i still have a this problem about a week.
thanks!
Hey David,
Thank you so much for pointing this out!
I’ve been using this for a couple of days now and it worked great, until I updated to iOS 5…
This doesn’t seem to work in iOS 5, I even put a NSLog in touchesBegan and it gets called (shows NSLog text in console) but the UIImagePickerController doesn’t focus.
Do you have any ideas why?
Thank you so much in advance!! 🙂
Unfortunately I don’t, I haven’t had a chance to revisit the code.