2013-03-12 96 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 
    } 
}