Set iOS device orientation programmatically. How?
Unsolved
Mobile and Embedded
-
-
@bogong you'll need to call objective c code, but it should be possible
from here:
UIInterfaceOrientation currentOrientation = [UIApplication sharedApplication].statusBarOrientation; NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait]; [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; [UIViewController attemptRotationToDeviceOrientation];
-
@J-Hilk I know it. I've tried it. The orientation after this code detecting like you set. But QML interface not redrawing. It's working perfectly when I am using it in native Objective-C/Swift but QML interface not redrawing even appeared signal about changed orientation. Only after phisical changing orientation it's wrking. I've already spent 2 weeks for finding cause of it.
-
Hello,I have encountered the same problem. May I ask if this problem has been resolved? I am unable to modify the device orientation of IOS
-
@bogong This is what I did for my program:
NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects]; UIWindowScene *scene = (UIWindowScene *)array[0]; UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:value]; [scene requestGeometryUpdateWithPreferences:geometryPreferences errorHandler:^(NSError * _Nonnull error) { NSLog(@"%@", error); }];
Where
value
is one ofUIInterfaceOrientationMaskLandscapeRight UIInterfaceOrientationMaskLandscapeLeft UIInterfaceOrientationMaskPortrait UIInterfaceOrientationMaskPortraitUpsideDown
Hope this helps.
A.T.