当我创建第二个AVCaptureSession时,自动对焦无法在第一个AVCaptureSession上运行.要创建的第二个会话是自动对焦工作的会话,第一个创建的会话不会自动对焦.
我希望任何一个会话都可以在另一个会话停止后自动对焦,就像两个会话的自动白平衡和自动曝光工作一样.如果您使用下面的示例代码观察日志窗口,您可以看到通过的键值观察消息; 但是在最高会话运行时从不改变焦点消息.
旁注:不幸的是我在我使用的第三方库中有一个错误,这使我无法简单地重新创建会话,因为我在它们之间切换(它正在泄漏其AVCaptureSessions,最终导致应用程序被杀死).完整的故事是这个库正在为我创建一个捕获会话,它有一个公共API来启动和停止会话,我希望创建另一个会话.下面的代码演示了问题,但没有使用第三方库.
我创建了一个测试应用程序,其中包含下面列出的代码和一个XIB文件,该文件有两个视图,一个在另一个之上,另一个按钮连接到switchSessions方法,用于演示该问题.
这可能与此处描述的问题有关, 焦点(自动对焦)不在相机中工作(AVFoundation AVCaptureSession),尽管没有提到两个捕获会话.
头文件:
#import <UIKit/UIKit.h>
@class AVCaptureSession;
@class AVCaptureStillImageOutput;
@class AVCaptureVideoPreviewLayer;
@class AVCaptureDevice;
@class AVCaptureDeviceInput;
@interface AVCaptureSessionFocusBugViewController : UIViewController {
IBOutlet UIView *_topView;
IBOutlet UIView *_bottomView;
AVCaptureDevice *_device;
AVCaptureSession *_topSession;
AVCaptureStillImageOutput *_outputTopSession;
AVCaptureVideoPreviewLayer *_previewLayerTopSession;
AVCaptureDeviceInput *_inputTopSession;
AVCaptureSession *_bottomSession;
AVCaptureStillImageOutput *_outputBottomSession;
AVCaptureVideoPreviewLayer *_previewLayerBottomSession;
AVCaptureDeviceInput *_inputBottomSession;
}
- (IBAction)switchSessions:(id)sender;
@end
Run Code Online (Sandbox Code Playgroud)
实施文件:
#import "AVCaptureSessionFocusBugViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface AVCaptureSessionFocusBugViewController ()
- (void)setupCaptureSession:(AVCaptureSession **)session
output:(AVCaptureStillImageOutput **)output
previewLayer:(AVCaptureVideoPreviewLayer **)previewLayer
input:(AVCaptureDeviceInput **)input
view:(UIView *)view;
- (void)tearDownSession:(AVCaptureSession **)session
output:(AVCaptureStillImageOutput **)output
previewLayer:(AVCaptureVideoPreviewLayer …Run Code Online (Sandbox Code Playgroud)