Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Set iOS device orientation programmatically. How?



  • Hello all!
    Is there any way in QT set the device orientation programmatically or by force?



  • 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)



  • @Gerhard The key word in my message PROGRAMMATICALLY OR BY FORCE. It's mean from code, not from application settings.


  • Moderators

    @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.



  • @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.


Log in to reply