|
| 1 | +// |
| 2 | +// AlertControllerForOF.cpp |
| 3 | +// iosOrientationExample |
| 4 | +// |
| 5 | +// Created by azuremous on 23/01/24 |
| 6 | +// |
| 7 | + |
| 8 | +#import "AlertControllerForOF.h" |
| 9 | + |
| 10 | +@implementation AlertControllerForOF { |
| 11 | + |
| 12 | +} |
| 13 | + |
| 14 | +- (id)initWithApp:(ofApp *)myApp { |
| 15 | + self = [super init]; |
| 16 | + if(self) { |
| 17 | + app = myApp; |
| 18 | + } |
| 19 | + return self; |
| 20 | +} |
| 21 | + |
| 22 | +- (void)dealloc { |
| 23 | + |
| 24 | +} |
| 25 | + |
| 26 | +- (void)showRotationOptions { |
| 27 | + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil |
| 28 | + message:@"Choose rotation" |
| 29 | + preferredStyle:UIAlertControllerStyleActionSheet]; |
| 30 | + |
| 31 | + UIAlertAction *portraitAction = [UIAlertAction actionWithTitle:@"Portrait" |
| 32 | + style:UIAlertActionStyleDefault |
| 33 | + handler:^(UIAlertAction *action) { |
| 34 | + self->app->rotateToPortrait(); |
| 35 | + }]; |
| 36 | + [alertController addAction:portraitAction]; |
| 37 | + |
| 38 | + UIAlertAction *portraitUpsideDownAction = [UIAlertAction actionWithTitle:@"Portrait Upside Down" |
| 39 | + style:UIAlertActionStyleDefault |
| 40 | + handler:^(UIAlertAction *action) { |
| 41 | + self->app->rotateToPortraitUpSideDown(); |
| 42 | + }]; |
| 43 | + [alertController addAction:portraitUpsideDownAction]; |
| 44 | + |
| 45 | + UIAlertAction *landscapeLeftAction = [UIAlertAction actionWithTitle:@"Landscape Left" |
| 46 | + style:UIAlertActionStyleDefault |
| 47 | + handler:^(UIAlertAction *action) { |
| 48 | + self->app->rotateToLandscapeLeft(); |
| 49 | + }]; |
| 50 | + |
| 51 | + [alertController addAction:landscapeLeftAction]; |
| 52 | + |
| 53 | + UIAlertAction *landscapeRightAction = [UIAlertAction actionWithTitle:@"Landscape Right" |
| 54 | + style:UIAlertActionStyleDefault |
| 55 | + handler:^(UIAlertAction *action) { |
| 56 | + self->app->rotateToLandscapeRight(); |
| 57 | + }]; |
| 58 | + [alertController addAction:landscapeRightAction]; |
| 59 | + |
| 60 | + UIAlertAction *autoRotationAction = [UIAlertAction actionWithTitle:@"Toggle Auto Rotation" |
| 61 | + style:UIAlertActionStyleDefault |
| 62 | + handler:^(UIAlertAction *action) { |
| 63 | + self->app->toggleAutoRotation(); |
| 64 | + |
| 65 | + }]; |
| 66 | + [alertController addAction:autoRotationAction]; |
| 67 | + |
| 68 | + UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" |
| 69 | + style:UIAlertActionStyleCancel |
| 70 | + handler:nil]; |
| 71 | + [alertController addAction:cancelAction]; |
| 72 | + |
| 73 | + if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { |
| 74 | + UIView * sourceView = ofxiOSGetGLParentView(); |
| 75 | + if (alertController.popoverPresentationController) { |
| 76 | + alertController.popoverPresentationController.sourceView = sourceView; |
| 77 | + alertController.popoverPresentationController.sourceRect = CGRectMake(sourceView.bounds.size.width/2, sourceView.bounds.size.height/2, 0, 0); |
| 78 | + alertController.popoverPresentationController.permittedArrowDirections = 0; |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + [ofxiOSGetUIWindow().rootViewController presentViewController:alertController animated:YES completion:nil]; |
| 83 | +} |
| 84 | + |
| 85 | + |
| 86 | +@end |
0 commit comments