我使用以下方法旋转相机,效果很好 这种方法是不旋转但设置摄像机视图,就像我们做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然后相机向左移动那么我怎么能解决这个问题