LightNight
LightNight

Reputation: 1625

Camera focus ios

I have crash message:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Setting focusPointOfInterest is not supported by this device. Use isFocusPointOfInterestSupported'

after code:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [device setFocusPointOfInterest:CGPointMake(100, 100)];
}

Is there any way to make focus like in Camera roll?

Upvotes: 2

Views: 2946

Answers (3)

Kevin
Kevin

Reputation: 771

A combination of answers, but this should help you out.

You need to convert the touch point from your touches began or touch gesture to a 0-1 scale.

So, check if your device has focus and then convert the point:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    // get device reference...

    if ([device isFocusPointOfInterestSupported]) {
        CGPoint point = [touch locationInView:self.myCameraView];
        float newX = point.x / self.myCameraView.frame.size.width;
        float newY = point.y / self.myCameraView.frame.size.height;
        [device setFocusPointOfInterest:CGPointMake(newX, newY)];
    }
    else {
        // Focus not supported
    }
}

Upvotes: 1

CreativeAbyss
CreativeAbyss

Reputation: 323

What JoeCortoPassi said.

so basically do a if loop to check if [device focusPointOfInterestSupported] returns true then do your [device setFocusPointOfInterest:CGPointMake(100, 100)];

EDIT:

code would be something like:

if ([device isFocusPointOfInterestSupported]){
    [device setFocusPointOfInterest:CGPointMake(100, 100)];
}else{
     // Not supported
}

hope this helps!

Upvotes: 0

JoeCortopassi
JoeCortopassi

Reputation: 5093

You need to check if setFocusPointOfInterest is accepted by using [device focusPointOfInterestSupported] as not all iOS devices support it, and if I remember right it differs by front/back camera as well

Upvotes: 0

Related Questions