我正在使用Apple AVCam代码示例。我已实现以下内容以使预览图层随设备一起旋转。一切都工作正常,但是,最初预览图层视图具有设置大小,因为界面底部有一个工具栏。旋转设备后,视图将变为全屏,覆盖工具栏。
-(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;
}
}
如何让预览图层视图旋转但保持界面内联?