You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在M1 Mac上禁用iOS UIKit应用的横屏显示?

解决方法
  • 调整Info.plist配置
    首先确认项目Info.plist中的UISupportedInterfaceOrientations数组仅包含UIInterfaceOrientationPortrait,移除其余所有方向的配置项。
    新增布尔类型的键UIApplicationSupportsIndirectInputEvents,值设为NO,该配置会禁用M1 Mac运行iOS App时的窗口缩放、横屏切换等桌面端交互特性。
  • 代码强制锁定竖屏方向
    若使用Scene生命周期,在SceneDelegate中添加如下代码:
    func windowScene(_ windowScene: UIWindowScene, didUpdate previousCoordinateSpace: UICoordinateSpace, interfaceOrientation previousInterfaceOrientation: UIInterfaceOrientation, traitCollection previousTraitCollection: UITraitCollection) {
        guard UIDevice.current.userInterfaceIdiom == .phone else { return }
        windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: .portrait))
    }
    
    若使用传统AppDelegate生命周期,添加如下方法:
    func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
        return .portrait
    }
    
  • 固定运行窗口大小
    在Xcode项目的「General」-「Deployment Info」配置区段,找到「Designed for iPhone」的Mac适配配置,勾选 Prefer window size matching iPhone device 选项,强制应用在M1 Mac上运行时固定为iPhone竖屏尺寸,禁止用户手动调整窗口。

内容的提问来源于stack exchange,提问作者XYZ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.08 13:18:02