2013-03-12 64 views
1

我有崩溃的消息:相机对焦IOS

*终止应用程序由于未捕获的异常“NSInvalidArgumentException”,理由是:“设置focusPointOfInterest不受此设备支持。使用isFocusPointOfInterestSupported”

代码之后:

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

有没有什么办法,使焦点像相机胶卷

+0

我不认为你真的了解重点的概念。你必须拍摄照片前将焦点设置,你不能这样做后 – s1m0n 2013-03-12 16:22:45

+0

你在哪里看到捕获照片代码在我的问题? – LightNight 2013-03-12 16:31:18

+0

等一下,我是否正确:你想在相机胶卷中设置照片的焦点? – s1m0n 2013-03-12 16:36:25

回答

0

您需要检查是否setFocusPointOfInterest通过使用[device focusPointOfInterestSupported]作为不是所有的iOS设备接受支持,如果我记得没错它由前/后摄像头的区别,以及

0

JoeCortoPassi说什么。

所以基本上做一个if循环来检查[device focusPointOfInterestSupported]是否返回true,然后执行[device setFocusPointOfInterest:CGPointMake(100,100)];

编辑:

代码将是这样的:

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

希望这有助于!

+1

您必须将CGPoint规格化为0-1的比例。 https://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html – Keller 2013-07-18 16:32:46

0

答案的组合,但这应该帮助你。

您需要将触摸开始时的触摸点或触摸手势转换为0-1刻度。

所以,请检查您的设备已聚焦,然后再转换点:

-(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 
    } 
}