我有一个横向方向的最终用户设计。用户不想/不需要纵向,需要避免iOS / Android上的自动方向更改。如何实现这一点?
我有一个横向方向的最终用户设计。用户不想/不需要纵向,需要避免iOS / Android上的自动方向更改。如何实现这一点?
SystemChrome
是您想要的内容。SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
]);
不幸的是,在我的应用程序中执行此操作时,方向将始终为landscapeRight
。
要锁定iOS设备的方向,您需要更改XCode项目的设置(在终端中使用命令'open ios/Runner.xcworkspace'打开它)。
void main() {
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft])
.then((_) {
runApp(new MyApp());
});
}
SystemChrome.setPreferredOrientations
返回一个 Future。等待它完成后,我们就可以启动我们的应用程序。
在你的main.dart文件中添加以下代码:
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
该代码用于设置应用程序只支持竖屏模式。