【发布时间】:2022-12-20 20:37:13
【问题描述】:
我希望能够仅以编程方式更改方向。按照我的意愿编写了旋转屏幕的功能。
UIInterfaceOrientation toIOSOrientation(ScreenOrientation desiredOrientaion) {
if (desiredOrientaion == ScreenOrientation::Landscape || desiredOrientaion == ScreenOrientation::LandscapeReversed) {
return UIInterfaceOrientation::UIInterfaceOrientationLandscapeLeft;
} else if (desiredOrientaion == ScreenOrientation::Portrait) {
return UIInterfaceOrientation::UIInterfaceOrientationPortrait;
} else {
return UIInterfaceOrientation::UIInterfaceOrientationPortrait;
}
}
void iOSTools::changeOrientation(ScreenOrientation desiredOrientaion) {
NSNumber* value = [NSNumber numberWithInt:toIOSOrientation(desiredOrientaion)];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
[UIViewController attemptRotationToDeviceOrientation];
}
但是我必须在应用程序清单中打开我的两个方向:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
</array>
如果我这样做,用户就可以使用这两个方向。如果我想禁止这个,我必须重写this 函数,但我应该如何在 Qt 中做到这一点?
【问题讨论】:
标签: ios objective-c qt orientation