0

我使用以下方法来旋转我的相机,它完美地工作这种方法是为了不旋转但设置相机视图,如果我们将 ipad 向上向下,那么相机将向上向下移动

-(void)rotateLayer{
    CALayer * stuckview = [[self captureManager] previewLayer];
    CGRect layerRect = [[[self view] layer] bounds];

    UIDeviceOrientation orientation =[[UIDevice currentDevice]orientation];

    switch (orientation) {
        case UIDeviceOrientationLandscapeLeft:
            stuckview.affineTransform = CGAffineTransformMakeRotation(M_PI+ M_PI_2); // 270 degress

            break;
        case UIDeviceOrientationLandscapeRight:
            stuckview.affineTransform = CGAffineTransformMakeRotation(M_PI_2); // 90 degrees
            break;
        case UIDeviceOrientationPortraitUpsideDown:
           stuckview.affineTransform = CGAffineTransformMakeRotation(M_PI); // 180 degrees
            break;
        default:
            stuckview.affineTransform = CGAffineTransformMakeRotation(0.0);
            [stuckview setBounds:layerRect];
            break;
    }
    [stuckview setPosition:CGPointMake(CGRectGetMidX(layerRect),CGRectGetMidY(layerRect))];
}

我有用于缩放相机的滑块,这就是我缩放的方式

-(void)sliderAction:(UISlider*)sender{



    howMuchToZoom = sender.value;
    CGAffineTransform affineTransform = CGAffineTransformMakeTranslation(sender.value, sender.value);
    affineTransform = CGAffineTransformScale(affineTransform, sender.value, sender.value);
    affineTransform = CGAffineTransformRotate(affineTransform, 0);
    [CATransaction begin];
    [CATransaction setAnimationDuration:.025];
    //previewLayer is object of AVCaptureVideoPreviewLayer
    [[[self captureManager]previewLayer] setAffineTransform:affineTransform];

    [CATransaction commit];
}

现在的问题是当我缩放然后缩放发生但是如果我将 ipad 向上移动然后相机向左向右移动所以我该如何解决这个问题

4

0 回答 0