我想阻止我的应用程序改变其方向,并迫使布局坚持“纵向”。
大体上是这样。省道,我放:
void main(){
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]);
runApp(new MyApp());
}
但当我使用Android模拟器旋转按钮时,布局“遵循”新的设备方向…
我怎么解决这个问题呢?
谢谢
首先主要导入这一点。飞镖文件
import 'package:flutter/services.dart';
然后不要复制粘贴,而是看(记住)和写下面的代码在主要。飞镖文件
强制进入纵向模式:
void main() {
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp,DeviceOrientation.portraitDown])
.then((_) => runApp(MyApp()),
);
在横屏模式下强制:
void main() {
SystemChrome.setPreferredOrientations(
[DeviceOrientation.landscapeLeft,DeviceOrientation.landscapeRight])
.then((_) => runApp(MyApp()),
);
要在iPad中强制竖屏,你还必须修改关键的UISupportedInterfaceOrientations~ iPad in ios/Runner/Info.plist:
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
这也可以通过XCode实现。
以上将在本地工作。为了通过XCode上传到App Store,你还需要将以下内容添加到Info.plist。这也可以通过检查“目标->常规->部署信息”下的“要求全屏”来完成。
<key>UIRequiresFullScreen</key>
<true/>
否则你会在上传时得到一个错误。