I have a UIView inside a UIViewController the UIView is used to capture photos using AVCaptureSession.
Hence I did not wanted my UIView to rotate when my device rotates, to implement this I wrote this piece of code.
-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
CGAffineTransform deltaTransform = coordinator.targetTransform;
CGFloat deltaAngle = atan2f(deltaTransform.b, deltaTransform.a);
CGFloat currentRotation = [[self.camera.layer valueForKeyPath:@"transform.rotation.z"] floatValue];
currentRotation += -1 * deltaAngle + 0.0001;
[self.camera.layer setValue:@(currentRotation) forKeyPath:@"transform.rotation.z"];
}
completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
CGAffineTransform currentTransform = self.camera.transform;
currentTransform.a = round(currentTransform.a);
currentTransform.b = round(currentTransform.b);
currentTransform.c = round(currentTransform.c);
currentTransform.d = round(currentTransform.d);
}];
}
In portrait mode my UIView opens up full screen when I rotate the rotation does not have any effect on my camera UIView and the other UIViews rotate smoothly, But the problem is on rotation to landscape mode my camera UIView is not full screen and takes random size on screen, What am I doing wrong?
Note: I have designed the view using storyboard