0
當我用iOS 6在iPad 3上啓動相機時,相機將執行對焦操作。這就是我如何與AVFoundation框架,這樣做:\在啓動時關閉相機對焦
//
// AppDelegate.h
//
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) AVCaptureSession *session;
@property (strong, nonatomic) AVCaptureVideoPreviewLayer *captureVideoPreviewLayer;
@property (strong, nonatomic) AVCaptureDevice *device;
@property (strong, nonatomic) AVCaptureDeviceInput *input;
@property(nonatomic, strong) AVCaptureStillImageOutput *stillImageOutput;
@end
//
// AppDelegate.m
//
@implementation AppDelegate
@synthesize session;
@synthesize captureVideoPreviewLayer;
@synthesize device;
@synthesize input;
@synthesize stillImageOutput;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
if (([device hasMediaType:AVMediaTypeVideo]) &&
([device position] == AVCaptureDevicePositionBack)) {
[device lockForConfiguration:&error];
if ([device isFocusModeSupported:AVCaptureFocusModeLocked]) {
device.focusMode = AVCaptureFocusModeLocked;
NSLog(@"Focus locked");
}
[device unlockForConfiguration];
}
session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetPhoto;
captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
[captureVideoPreviewLayer setAffineTransform:CGAffineTransformMakeRotation(-M_PI/2)];
input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (!input) {
// Handle the error appropriately.
NSLog(@"ERROR: trying to open camera: %@", error);
}
[session addInput:input];
stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil];
[stillImageOutput setOutputSettings:outputSettings];
[session addOutput:stillImageOutput];
[session startRunning];
return YES;
}
我專門就AVDevice
在啓動時(device.focusMode = AVCaptureFocusModeLocked;
)鎖定對焦,但相機啓動時,它會執行對焦操作。在我的應用程序中,我不希望發生這種情況,以便進行相機校準。
我該如何避免焦點在相機初始化上被觸發?