i'm in need to force the orientation of the interface in landscape is the app runs in an iPad device.
I have found some code in stackoverflow that call
let value = UIInterfaceOrientation.landscapeRight.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
in a buttons and it should force the orientation of the device but i experienced no change in my app. the set to landscaperight does absolutely nothing.
How can i achieve the rotation?
Related
I have a Qt / QML application on iOS. It is coded in C++ but I can include objective-c code in it.
I can change programmatically the orientation of the screen, which changes the orientation of the application, without changing the orienation of the iPad, and the user has to turn it when he notices the change of orientation of the screen.
I do that as I need to force the orientation depending on what I display on the application.
What I need to do now is to lock the automatic change of orientation (due to physical change) as I need it to be landscape sometimes and portrait other times.
To change the orientation programmatically, I found the above solution which works:
in my plist file, orientations must be allowed:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
in my C++ code where I can insert objective-c:
void setScreenOrientation(bool inIsPortrait)
{
if(#available(iOS 16, *))
{
NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
UIWindowScene *scene = (UIWindowScene *)array[0];
UIInterfaceOrientationMask newOrientation;
if(inIsPortrait)
newOrientation = UIInterfaceOrientationMaskPortrait;
else
newOrientation = UIInterfaceOrientationMaskLandscapeRight;
UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:newOrientation];
[scene requestGeometryUpdateWithPreferences:geometryPreferences errorHandler:^(NSError * _Nonnull error) { }];
}
else
{
//does not work on iOS 16, outputs following error:
//[Orientation] BUG IN CLIENT OF UIKIT: Setting UIDevice.orientation is not supported. Please use UIWindowScene.requestGeometryUpdate(_:)
NSNumber *newOrientation;
if(inIsPortrait)
newOrientation = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
else
newOrientation = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
[[UIDevice currentDevice] setValue:newOrientation forKey:#"orientation"];
}
}
}
So with that, when I want to change the orientation from portrait to landscape or vice versa, I just call the function with the correct parameter.
The problem is that when I physically turn the iPad, the screen automatically changes its orientation due to the plist file. So when I force to landscape, the user sees the change so turns its iPad, but if he turns back to portrait, the automatic change will put back the screen to portrait, without calling my function of course.
I can't remove the orientations from the plist file as they are required if I want to change it programmatically.
But I would like to lock the screen in the selected orientation at the end of the function, and of course, unlock it at the beginning, so that physically turn the iPad won't change the screen orientation.
I found solutions with the function "shouldAutorotate" but it has to be overwritten and called in viewDidLoad or supportedInterfaceOrientationsForWindow which are specific to an objective-c implementation and architecture.
I found : Lock orientation with native Objective-C code from Qt
but I can't do that in my code as I don't have any ViewController, ... it's a Qt / QML application.
I would like to have something that I can call in my function, something to change the supported orientations, so modify "supportedInterfaceOrientationsForWindow" by calling it directly in a function. Something like:
[[UIApplication ???] supportedInterfaceOrientationsForWindow] = UIInterfaceOrientationMaskPortrait; //or UIInterfaceOrientationMaskLandscapeRight depending on what I need
or any other instructions but without having to override supportedInterfaceOrientationsForWindow.
Thanks
Working on a cross platform app in Qt. I need to be able to force the screen orientation for a couple of pages. I've found a way to do this for Android, but I can't find anything for iOS.
Is there any way to force set the screen orientation in iOS?
Better yet, is there a single call that will set the screen orientation for any given mobile platform?
Thanks!
Have a look here:
https://doc.qt.io/qt-5/qml-qtquick-window-screen.html#orientation-attached-prop
You could write the Screen.orientation (or Screen.primaryOrientation) property into your own property and use the onChanged event handler to get a Signal, eg:
readonly property var screenOrientation: Screen.orientation
onScreenOrientationChanged: {
console.log("Orientation Changed!")
}
Is famo.us currently suitable for landscape oriented development ? I'm especially concerned in making it to work on iPhone. As I saw unfortunately the iOS < 7.1 safari takes a quarter of the height just for the navigation bar. Hiding it completely involves adding the app (webpage) to the main screen.
Famo.us is most certainly suitable for landscape oriented Design. The sizing feature of 'undefined' for Famo.us surfaces and the origin constraints on modifiers allow for designs to fit any number of device sizes and orientations.
Detecting an orientation change using only Famo.us can be done using something similar to the following..
Engine.on('resize',function(){
size = context.getSize();
if (size[0] > size[1]) {
// landscape
} else {
// portrait
}
});
Right now there isn't a way to automagically hide browser chrome without saving to home screen with the proper meta tags for ios and android. Alternatively, a Famo.us app can be wrapped in Cordova and distributed on AppStore and Google's Play Store, and the app will display in full screen without browser chrome.
On Google Glass, calling Camera via Intent as below immediately takes a picture instead of showing camera view finder.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PICTURE_REQUEST);
Does anyone know a way to show a view finder (and "Tap to Scan" text overlaying) exactly as Google Glass Settings app does when letting you scan the QRCode on (https://glass.google.com/myglass) to connect to Wifi?
You would have to have a SurfaceView that shows the camera preview, instead of letting the camera app do the work.
See Android Camera Surface View for how to do this in Android (code will also work on Glass).
On click of a Button
I have created a List that comes out on the next Screen
Now i want to set it as Landscape Portrait
If the Height in Resolution is greater than its Width how do I achieve it?
With Blackberry, you cannot set the device orientation to landscape/portrait, unless the user holds in that way and then you set it in the app.
You can set the device to landscape using the following code.
Ui.getUiEngineInstance().setAcceptableDirections(Display.DIRECTION_LANDSCAPE);
Remember, this code wont work if you are holding the device in portrait mode. Turn the device into landscape mode and then run this code and the app is set to landscape mode from then on.