Subversion Repositories tpanel

Rev

Rev 245 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 245 Rev 247
Line 10... Line 10...
10
#define O_FACE_UP               15
10
#define O_FACE_UP               15
11
#define O_FACE_DOWN             16
11
#define O_FACE_DOWN             16
12
 
12
 
13
bool TIOSRotate::mPortrait{false};
13
bool TIOSRotate::mPortrait{false};
14
 
14
 
15
@interface ViewController : UIViewController
-
 
16
 
-
 
17
@end
-
 
18
 
-
 
19
@implementation ViewController
-
 
20
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
-
 
21
{
-
 
22
    if (TIOSRotate::getAllowedOrientation())
-
 
23
        return UIInterfaceOrientationMaskPortrait;
-
 
24
 
-
 
25
    return UIInterfaceOrientationMaskLandscape;
-
 
26
}
-
 
27
 
-
 
28
@end
-
 
29
 
-
 
30
ViewController *_ctrl = nil;
-
 
31
 
-
 
32
TIOSRotate::TIOSRotate()
15
TIOSRotate::TIOSRotate()
33
{
16
{
34
    _ctrl = [[ViewController alloc]init];
-
 
35
}
17
}
36
 
18
 
37
void TIOSRotate::rotate(int dir)
19
void TIOSRotate::rotate(int dir)
38
{
20
{
39
    NSNumber *value = nil;
21
//    NSNumber *value = nil;
-
 
22
    float value = 0.0;
40
 
23
 
41
    switch(dir)
24
    switch(dir)
42
    {
25
    {
43
        case O_LANDSCAPE:           value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight]; break;
26
        case O_LANDSCAPE:           value = UIInterfaceOrientationMaskLandscapeRight; break;
44
        case O_REVERSE_LANDSCAPE:   value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft]; break;
27
        case O_REVERSE_LANDSCAPE:   value = UIInterfaceOrientationMaskLandscapeLeft; break;
45
        case O_PORTRAIT:            value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait]; break;
28
        case O_PORTRAIT:            value = UIInterfaceOrientationMaskPortrait; break;
46
        case O_REVERSE_PORTRAIT:    value = [NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown]; break;
29
        case O_REVERSE_PORTRAIT:    value = UIInterfaceOrientationMaskPortraitUpsideDown; break;
47
    }
30
    }
48
 
31
 
-
 
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); }];
-
 
36
}
-
 
37
 
-
 
38
void TIOSRotate::automaticRotation(bool allow)
-
 
39
{
-
 
40
    if (allow)
49
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
41
        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
-
 
42
    else
50
    [UIViewController attemptRotationToDeviceOrientation];
43
        [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
51
}
44
}