Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Set iOS device orientation programmatically. How?
Forum Update on Monday, May 27th 2025

Set iOS device orientation programmatically. How?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
8 Posts 5 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bogong
    wrote on last edited by
    #1

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

    J.HilkJ T 2 Replies Last reply
    0
    • GerhardG Offline
      GerhardG Offline
      Gerhard
      wrote on last edited by
      #2

      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

      B 1 Reply Last reply
      0
      • GerhardG Gerhard

        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)

        B Offline
        B Offline
        bogong
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • B bogong

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

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @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];
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          B 2 Replies Last reply
          0
          • J.HilkJ J.Hilk

            @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];
            
            B Offline
            B Offline
            bogong
            wrote on last edited by bogong
            #5

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

            1 Reply Last reply
            0
            • J.HilkJ J.Hilk

              @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];
              
              B Offline
              B Offline
              bogong
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jiang_chao
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • B bogong

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

                  T Offline
                  T Offline
                  TheoSys
                  wrote on last edited by
                  #8

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

                  UIInterfaceOrientationMaskLandscapeRight
                  UIInterfaceOrientationMaskLandscapeLeft
                  UIInterfaceOrientationMaskPortrait
                  UIInterfaceOrientationMaskPortraitUpsideDown
                  

                  Hope this helps.

                  A.T.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved