Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
243 andreas 1
#include "tiosrotate.h"
2
#import <Foundation/Foundation.h>
3
#import <UIKit/UIKit.h>
4
 
5
#define O_UNDEFINED             -1
6
#define O_LANDSCAPE             0
7
#define O_PORTRAIT              1
8
#define O_REVERSE_LANDSCAPE     8
9
#define O_REVERSE_PORTRAIT      9
10
#define O_FACE_UP               15
11
#define O_FACE_DOWN             16
12
 
245 andreas 13
bool TIOSRotate::mPortrait{false};
14
 
15
TIOSRotate::TIOSRotate()
16
{
17
}
18
 
243 andreas 19
void TIOSRotate::rotate(int dir)
20
{
247 andreas 21
//    NSNumber *value = nil;
22
    float value = 0.0;
243 andreas 23
 
24
    switch(dir)
25
    {
247 andreas 26
        case O_LANDSCAPE:           value = UIInterfaceOrientationMaskLandscapeRight; break;
27
        case O_REVERSE_LANDSCAPE:   value = UIInterfaceOrientationMaskLandscapeLeft; break;
28
        case O_PORTRAIT:            value = UIInterfaceOrientationMaskPortrait; break;
29
        case O_REVERSE_PORTRAIT:    value = UIInterfaceOrientationMaskPortraitUpsideDown; break;
243 andreas 30
    }
31
 
247 andreas 32
    NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
33
    UIWindowScene *scene = (UIWindowScene *)array[0];
34
    UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:value];
35
    [scene requestGeometryUpdateWithPreferences:geometryPreferences errorHandler:^(NSError * _Nonnull error) { NSLog(@"%@", error); }];
243 andreas 36
}
247 andreas 37
 
38
void TIOSRotate::automaticRotation(bool allow)
39
{
40
    if (allow)
41
        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
42
    else
43
        [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
44
}