我正在使用AVFoundation
添加相机预览。平滑方向更改(纵向到横向)时出现问题,更改旋转(~30deg)时会出现跳转。
我想更顺利地做到这一点。
viewWillTransitionMethod:
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
UIInterfaceOrientation targetOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if ([self.session isRunning]) {
[CATransaction begin];
[CATransaction setAnimationDuration:[context transitionDuration]];
[CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
if (targetOrientation==UIInterfaceOrientationLandscapeLeft) {
self.previewLayer.transform = CATransform3DMakeRotation(M_PI_2, 0.0, 0.0, 1.0);
} else if (targetOrientation==UIInterfaceOrientationLandscapeRight) {
self.previewLayer.transform = CATransform3DMakeRotation(-M_PI_2, 0.0, 0.0, 1.0);
} else {
self.previewLayer.transform = CATransform3DMakeRotation(0.0, 0.0, 0.0, 1.0);
}
[self.previewLayer setFrame:self.cameraPreview.frame];
[CATransaction commit];
}