I'm developing an iOS application with latest SDK.
I'm working with camera and I want to make zoom. To do it I have this code:
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setUpVideo];
}
- (void)setUpVideo
{
NSLog(@"Set up video");
UIView *view = [self videoPreviewView];
CALayer *viewLayer = [view layer];
[viewLayer setMasksToBounds:YES];
AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:DataExchanger.cameraManager.captureSession];
CGRect bounds = [view bounds];
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
CGAffineTransform t;
if (orientation == UIInterfaceOrientationLandscapeRight)
{
t = CGAffineTransformMakeRotation(-M_PI_2);
bounds = CGRectMake(bounds.origin.x, bounds.origin.y,
bounds.size.height, bounds.size.width);
}
[newCaptureVideoPreviewLayer setFrame:bounds];
[newCaptureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
newCaptureVideoPreviewLayer.position = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
newCaptureVideoPreviewLayer.affineTransform = t;
[viewLayer insertSublayer:newCaptureVideoPreviewLayer below:[[viewLayer sublayers] objectAtIndex:0]];
CGAffineTransform currentTransform = CGAffineTransformIdentity;
CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, 2.0f, 2.0f);
view.transform = newTransform;
}
But I see a different between the zoom image and the same image without zoom. Without moving the camera I see that the center shifted to the left bottom when I made zoom.
Maybe I have to move videoView
centers with a formula that calculates its new center using the scale.
Do you know how to fix that?