2016-04-11 4 views
0

Ich habe einen View-Controller, in dem ich eine UIView Vollbildgröße hinzugefügt habe, In dieser UIView habe ich die AVCapturesession, die mir hilft, Fotos zu erfassen, Mein Ansicht Controller öffnet gut im Hochformat Modus, öffnet sich aber abrupt im Querformat.So öffnen Sie meine Anwendung im Querformat

Der Code wird wie folgt

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.view.backgroundColor = [UIColor whiteColor]; 
    [[UIDevice currentDevice]beginGeneratingDeviceOrientationNotifications]; 
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil]; 
    self.camera.userInteractionEnabled = YES; 
    UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(handlePinchGesture:)]; 
    pinchGesture.delegate=self; 
    [self.camera addGestureRecognizer:pinchGesture]; 
    [self.navigationController setNavigationBarHidden:YES animated:YES]; 
} 

Die Kamera die UIView ist, die Eigentum meiner UIViewController ist,

Wieder

-(void) viewDidAppear:(BOOL)animated 
{ 
    AVCaptureSession *session = [[AVCaptureSession alloc] init]; 
    session.sessionPreset = AVCaptureSessionPresetMedium; 

    CALayer *viewLayer = self.camera.layer; 
    NSLog(@"viewLayer = %@", viewLayer); 
    captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session]; 

    captureVideoPreviewLayer.frame = self.camera.layer.bounds; 
    [self.camera.layer addSublayer: captureVideoPreviewLayer]; 
    device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 
    NSError *error = nil; 
    AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error]; 
    if (!input) { 
    // Handle the error appropriately. 
    NSLog(@"ERROR: trying to open camera: %@", error); 
    } 
    [session addInput:input]; 

    [session startRunning]; 
    stillImageOutput = [[AVCaptureStillImageOutput alloc] init]; 
    NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil]; 
    [stillImageOutput setOutputSettings:outputSettings]; 

    [session addOutput:stillImageOutput]; 

    isUsingFlash = NO; 
    isUsingFrontFacingCamera = NO; 
    effectiveScale = 1.0; 
} 

Meine Ansicht öffnet in Landscape-Modus falsch sobald ich zum Hochformat rotiere, wird es gut und wieder zu Drehung, um zu landschaftlich, es funktioniert gut, nur es startet nicht richtig im Querformat, warum?

Hier bin ich Einstellung der Root-Ansicht-Controller,

sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
cameraFirstController = [sb instantiateViewControllerWithIdentifier:@"FirstViewController"]; 
cameraFirstController.delegate = self; 
nav = [[CustomNavigationController alloc]initWithRootViewController:cameraFirstController]; 
[self.viewController presentViewController:nav animated:YES completion:nil]; 
+0

können Sie Code hinzufügen, wo Sie rootViewController einstellen. –

+0

Ich habe den Code in der bearbeiteten Antwort hinzugefügt. Bitte prüfe –

Antwort

0

scheint Problem Reihenfolge der Anrufe ist, wenn Sie das Fenster einrichten. Sie müssen makeKeyAndVisible anrufen, bevor Sie die rootViewController zuweisen.

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 
[self.window makeKeyAndVisible]; 
self.window.rootViewController = self.YourViewController;