Set iOS device orientation programmatically. How?
-
wrote on 27 Apr 2021, 17:55 last edited by
Hello all!
Is there any way in QT set the device orientation programmatically or by force? -
wrote on 27 Apr 2021, 20:15 last edited by
Hello,
add the following entry in the .plist file
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>Gerhard
(sorry for my english) -
Hello,
add the following entry in the .plist file
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>Gerhard
(sorry for my english) -
@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];
-
@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];
wrote on 1 May 2021, 17:51 last edited by bogong 5 Jan 2021, 17:55@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.
-
@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];
wrote on 1 May 2021, 18:00 last edited by@J-Hilk but never the less - thx for reply. If, not if, when I get success with it - will publish example. Going to get next iteration of this issue tomorrow.
-
wrote on 13 Oct 2023, 05:47 last edited by
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
-
wrote on 15 Oct 2023, 16:43 last edited by
@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.