iOS强制闪屏竖屏

本文介绍了解决iOS应用启动闪屏显示横屏问题的方法。通过在部署信息中仅选择竖屏方向,并在AppDelegate中添加代码支持所有非倒置方向,确保应用启动时以竖屏显示,同时允许后续的屏幕旋转。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

手机App内部支持横竖屏切换,但是闪屏只支持竖屏,应该怎么设置呢?

开发过程中忽略了调试设备的转屏开关问题,设备转屏开关是关闭的,后来才发现,打开设备转屏开关后,当设备横屏进入时,App的闪屏也会横屏显示,没对竖屏闪屏做适配处理,只支持闪屏横屏显示,想了想,后来发现以下处理方式有效可行。

00xx1

将TARGET->General->Deployment Info->Device Orientations下,只选Portrait。

也就说说,在这里,只设置支持的屏幕方向为竖屏。

这样设置的话,应用就只支持竖屏,那么怎么让应用支持其他转屏方式呢,需要同时做00xx2中的设置。

00xx2

在AppDelegate里,添加设置应用支持的转屏方式的代码:

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

00xx1保证了应用进入时竖屏进入,00xx2保证了应用进入后,仍然支持其他方向的转屏。这样就解决了应用进入时的方向和应用进入后支持的转屏方向,在强制闪屏横屏的同时,不影响App内部的屏幕旋转。

<view class="video" v-if="item && item.video_url"> <Player style="width: 100%;" :key="index" :index="index" :video-url="item.video_url" :cover-url="item.cover_url" @play="handleVideoPlay" /> </view> handleVideoPlay(index) { if(this.currentIndex !== null && this.currentIndex !== index) { const prevVideo = uni.createVideoContext('video'+this.currentIndex, this) prevVideo.pause() prevVideo.exitFullScreen() } this.currentIndex = index }, <template> <view class="video-box"> <video style="width: 100%;" :id="'video'+index" :src="videoUrl" :poster="coverUrl" :controls="true" :show-fullscreen-btn="true" :show-center-play-btn="true" :enable-progress-gesture="true" @fullscreenchange="handleFullscreen" @play="onPlay" @pause="onPause" @click="toggleFullscreen" ></video> </view> </template> <script> export default { props: { videoUrl: String, coverUrl: String, index: Number }, methods: { toggleFullscreen() { // const videoCtx = uni.createVideoContext('video'+this.index, this) // if(this.isFullscreen) { // videoCtx.pause() // videoCtx.exitFullScreen() // } else { // // 关键修改:移除方向参数 // videoCtx.requestFullScreen() // } const videoCtx = uni.createVideoContext('video'+this.index, this) // #ifdef APP-PLUS plus.screen.lockOrientation('portrait-primary') // 临时允许横屏 // #endif videoCtx.requestFullScreen() }, handleFullscreen(e) { this.isFullscreen = e.detail.fullScreen // #ifdef APP-PLUS if(!e.detail.fullScreen) { plus.screen.lockOrientation('portrait-primary') } // #endif // #ifdef APP-PLUS && IOS plus.screen.unlockOrientation() plus.navigator.setStatusBarStyle('dark') // #endif }, onPlay() { this.$emit('play', this.index) }, onPause() { this.$emit('pause', this.index) } }, data() { return { isFullscreen: false } } } </script> <style> .video-box{ width: 100%; height: 100vh; /* 强制占满幕高度 */ } </style> uniapp 安卓点击视频播放全按钮后 也是横屏的 怎么在代码里禁止
最新发布
07-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Morris_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值