Extend OpenVulkanoOrientationLockableViewController

This commit is contained in:
Georg Hagen
2024-06-16 12:08:43 +02:00
parent 853768b0dd
commit c7a4b4a684
2 changed files with 23 additions and 2 deletions

View File

@@ -29,6 +29,17 @@
}
}
-(CGFloat)getOrientation {
if (_rotationLockedView == nil) return 0;
return [[_rotationLockedView.layer valueForKeyPath:@"transform.rotation.z"] floatValue];
}
-(void)setOrientation:(CGFloat)angle {
if (_rotationLockedView != nil) {
[_rotationLockedView.layer setValue:@(angle) forKeyPath:@"transform.rotation.z"];
}
}
-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
@@ -38,10 +49,10 @@
CGAffineTransform deltaTransform = coordinator.targetTransform;
CGFloat deltaAngle = atan2f(deltaTransform.b, deltaTransform.a);
CGFloat currentRotation = [[_rotationLockedView.layer valueForKeyPath:@"transform.rotation.z"] floatValue];
CGFloat currentRotation = [self getOrientation];
// Adding a small value to the rotation angle forces the animation to occur in a the desired direction, preventing an issue where the view would appear to rotate 2PI radians during a rotation from LandscapeRight -> LandscapeLeft.
currentRotation += -1 * deltaAngle + 0.0001;
[_rotationLockedView.layer setValue:@(currentRotation) forKeyPath:@"transform.rotation.z"];
[self setOrientation:currentRotation];
} completion:^(id <UIViewControllerTransitionCoordinatorContext> context) {
// Integralize the transform to undo the extra 0.0001 added to the rotation angle.

View File

@@ -16,6 +16,8 @@
@property (nonatomic, strong) OpenVulkanoView* openVulkanoView;
-(id)init;
-(void*) makeGraphicsApp;
@end
@@ -24,4 +26,12 @@
@property (nonatomic, strong) UIView* rotationLockedView;
//@property CGFloat baseRotation;
-(id)init;
-(CGFloat)getOrientation;
-(void)setOrientation:(CGFloat)angle;
@end