0

I am working with Apple AVCam code example. I have implemented the following to get the preview layer to rotate with the device. Everything is working fine, however, initially the preview layer view has a set size because there is a toolbar on the bottom of the interface. When the device is rotated, the view becomes full screen, covering the toolbar.

-(BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return /*UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown |*/
    UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

    switch (toInterfaceOrientation) {
        /*case UIDeviceOrientationPortrait:
            [videoPreviewView.layer setAffineTransform:CGAffineTransformMakeRotation(0)];
            break;

        case UIDeviceOrientationPortraitUpsideDown:
            [videoPreviewView.layer setAffineTransform:CGAffineTransformMakeRotation(M_PI)];
            break;*/

        case UIDeviceOrientationLandscapeLeft:
            [videoPreviewView.layer setAffineTransform:CGAffineTransformMakeRotation(/*-M_PI/2*/0)];
            break;

        case UIDeviceOrientationLandscapeRight:
            [videoPreviewView.layer setAffineTransform:CGAffineTransformMakeRotation(/*M_PI/2*/M_PI)];
            break;

        default:
            break;
    }
    videoPreviewView.layer.frame = self.view.bounds;

    CGAffineTransform transform = [videoPreviewView.layer affineTransform];

    NSLog(@"videoPreviewView:transform: [%f %f,%f,%f,%f,%f",transform.a, transform.b,
          transform.c, transform.d, transform.tx, transform.ty);
    NSLog(@"previewView.layer.frame width: %f height: %f",videoPreviewView.layer.frame.size.width,
          videoPreviewView.layer.frame.size.height);
}


-(void) viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:YES];

    //Get Preview Layer connection
    AVCaptureConnection *previewLayerConnection=self.captureVideoPreviewLayer.connection;

    if ([previewLayerConnection isVideoOrientationSupported]){
        [previewLayerConnection setVideoOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
        self.captureVideoPreviewLayer.frame=self.view.bounds;
    }
}

How can I get the preview layer view to rotated but keep the interface inline?

4

0 回答 0