相机预览更平滑更改方向Ipad

时间:2017-03-16 09:00:15

标签: ios objective-c ipad animation camera

我正在使用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];
        }

0 个答案:

没有答案