在uni-app的APP端使用plus.screen.lockOrientation切换横竖屏后快速多次点击导航栏的返回按钮会偶尔出现闪退现象
在uni-app的APP端使用plus.screen.lockOrientation切换横竖屏后快速多次点击导航栏的返回按钮会偶尔出现闪退现象
| 开发环境 | 版本号 | 项目创建方式 |
|---|---|---|
| Windows | 11 | HBuilderX |
操作步骤:
- 创建
usePageOrientation.ts文件
export function usePageOrientation() {
const lockLandscape = () => {
// #ifdef APP-PLUS
plus.screen.lockOrientation('landscape-primary')
// #endif
}
const restorePortrait = () => {
// #ifdef APP-PLUS
plus.screen.lockOrientation('portrait-primary')
// #endif
}
return {
lockLandscape,
restorePortrait,
}
}
- 在a页面引入
onShow中执行restorePortrait
import { usePageOrientation } from '@/hooks/usePageOrientation'
const { lockLandscape, restorePortrait } = usePageOrientation()
onShow(() => {
restorePortrait()
})
- 从a页面跳转到b页面,页面设置为横屏
import { usePageOrientation } from '@/hooks/usePageOrientation'
const { lockLandscape, restorePortrait } = usePageOrientation()
onLoad((options: any) => {
lockLandscape()
})
更多关于在uni-app的APP端使用plus.screen.lockOrientation切换横竖屏后快速多次点击导航栏的返回按钮会偶尔出现闪退现象的实战教程也可以访问 https://www.itying.com/category-93-b0.html
1 回复


