New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'tap to focus' functionality #47

Closed
nickw444 opened this Issue Sep 24, 2015 · 9 comments

Comments

Projects
None yet
3 participants
@nickw444

nickw444 commented Sep 24, 2015

Since there is no ability to access the internals of the scanner (AVCaptureSession, AVCaptureDevice), it is technically impossible to extend the library to add tap to focus.

Is there any scope for getters and setters for the AVCaptureSession and AVCaptureDevice to be made public?

Cheers

@mikebuss

This comment has been minimized.

Owner

mikebuss commented Sep 24, 2015

Hey @nickw444, thanks for the suggestion. I can definitely add tap-to-focus functionality to MTBBarcodeScanner, but I don't have any plans to expose the capture session or device.

I'm hoping to keep the library as easy to use as possible, which means abstracting some of these details away from the user and exposing easier interfaces. For example with the torch functionality, we almost chose to expose the AVCaptureDeviceInput object, which would make turning on the torch as simple as:

if ([captureDeviceInput.device hasTorch]) {
    if ([captureDeviceInput.device lockForConfiguration:nil] == YES) {
        [captureDeviceInput.device setTorchMode:AVCaptureTorchModeOn];
        [captureDeviceInput.device unlockForConfiguration];
    }
}

But instead we exposed a simpler way, which is now:

self.scanner.torchMode = MTBTorchModeOn;

This takes away some of the functionality (i.e. we can't tell if the device actually has a torch), but for the majority of use-cases that's OK.

If you think adding tap-to-focus would be useful, I can maybe add a tapToFocus boolean to the library to enable this. Were you thinking of implementing this in a way similar to this?:

  • User taps the previewView
  • Based on the tap location, the focusPointOfInterest is set to a window around the touch

Or were there other properties you wanted to change based on user interaction?

Pull requests are also welcome if you'd like to implement this. I should be able to get to it in the next few weeks, but some people have tight deadlines and choose to take a swing themselves!

@nickw444

This comment has been minimized.

nickw444 commented Sep 25, 2015

Hey @mikebuss that's a fair reason for hiding the internals. Simple is better!

Implementing touch to focus similar to how the torch is implemented is a great way to go about it - no need for the user to rely on their own implementation. I like it!

I can only see a single issue with this - user feedback. It would be nice to show the user where they touched, and, not every app will do this the same - they might want to use different UI Features, or just not show the user at all.

My suggestion is that upon touch handle, a block/callback is triggered, which allows the user to provide their own feedback view drawing code, which will paint the feedback square (or whatever view they wish) over the preview view. (and at the same time MTBBarcodeScanner handles the focusing)

This would allow MTBBarcodeScanner to handle the internals of focusing, whilst still allowing the user to provide their own custom UI.

What are your thoughts on this method?

I'll see if I can find some time to implement this (since it would improve 2 apps using this library), however i'm also pretty tied up at the moment.

@mikebuss

This comment has been minimized.

Owner

mikebuss commented Sep 25, 2015

Yes that sounds great.

@mikebuss mikebuss changed the title from Ability to access AVCaptureSession/AVCaptureDevice to Add 'tap to focus' functionality Sep 26, 2015

@mikebuss mikebuss added the feature label Oct 1, 2015

@jaybowong

This comment has been minimized.

Contributor

jaybowong commented Oct 20, 2015

Want this feature so much!

@jaybowong

This comment has been minimized.

Contributor

jaybowong commented Jan 18, 2016

@nickw444 Have you implemented this? How about a PR? I think a lot of people need this feature and it can help a lot.

It's quite often to me that It doesn't focus when scanning a bar code (e.g. a bar code on the back of a book).

@mikebuss

This comment has been minimized.

Owner

mikebuss commented Jan 19, 2016

@jaybowong I can take a stab at this over the weekend. I will update this ticket with the results.

@mikebuss mikebuss closed this in 9a04e62 Jan 19, 2016

@mikebuss

This comment has been minimized.

Owner

mikebuss commented Jan 19, 2016

I added an initial implementation for this. When the user taps the screen, MTBBarcodeScanner will now set the focusPointOfInterest to the point the user tapped and call a block named didTapToFocusBlock(), which can be overridden for custom drawing.

The full details can be found here. The README also has documentation on this.

Please feel free to submit a PR with any improvements.

@jaybowong

This comment has been minimized.

Contributor

jaybowong commented Jan 20, 2016

Thanks @mikebuss 👍
Can't wait to try this!

@nickw444

This comment has been minimized.

nickw444 commented Jan 20, 2016

Awesome stuff. I'll be sharing a gist as soon as I can which uses this and adds a apple camera like focus square.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment