当前位置: 首页 > news >正文

网站风格主要包括关键词优化排名公司

网站风格主要包括,关键词优化排名公司,医疗器械分为哪三类,官方网站建设实训心得文章目录 问题原因:解决方案: 今天刚遇到的问题,横屏的页面完成操作后跳转页面后,自定义的tabbar样式乱了,跑到最顶了,真机调试后发现navbar跑到手机状态栏了,它正常应该跟右边胶囊一行。 知道问…

文章目录

      • 问题原因:
      • 解决方案:

今天刚遇到的问题,横屏的页面完成操作后跳转页面后,自定义的tabbar样式乱了,跑到最顶了,真机调试后发现navbar跑到手机状态栏了,它正常应该跟右边胶囊一行。

在这里插入图片描述
知道问题了就好办了,先分析

正常的屏幕显示应该是:

  • 竖屏:导航栏高度 = 状态栏高度 + 44px(内容区)
  • 横屏:导航栏高度 = 44px(仅内容区)

问题原因:

  • 屏幕旋转时,系统信息(如状态栏高度)会发生变化
  • 在横竖屏切换过程中,获取系统信息可能存在时序问题,导致获取到的状态栏高度不准确

解决方案:

  • 监听屏幕旋转事件 wx.onWindowResize
  • 通过比较窗口宽高来判断是否横屏:windowWidth > windowHeight
  • 在横屏时将状态栏高度设置为0,竖屏时使用系统实际状态栏高度
  • 使用 setTimeout 延迟更新导航栏状态,确保系统信息已完全更新
  • 在组件销毁时,记得解绑旋转事件监听器 wx.offWindowResize()

下面是具体custom-navbar组件的代码,这里只是适用我的项目,应该不是完美的方案,有更好的方案欢迎大家沟通

custom-navbar.wxml

<view class="navbar-container"><!-- 导航栏主体 --><view class="navbar {{isLandscape ? 'landscape' : ''}}"><!-- 状态栏占位 --><view class="status-bar" style="height: {{statusBarHeight}}px"></view><!-- 导航栏内容 --><view class="navbar-content"><view class="left"><view wx:if="{{showBack}}" class="back-icon" bind:tap="onBack"><t-icon name="chevron-left" class="nav-icon" /></view><view wx:if="{{showHome}}" class="home-icon" bind:tap="onGoHome"><t-icon name="home" class="nav-icon" /></view></view><view class="center"><text>{{title}}</text></view><view class="right"></view></view></view><!-- 占位元素 --><view class="navbar-placeholder" style="height: {{isLandscape ? 44 : (44 + statusBarHeight)}}px"></view>
</view>

custom-navbar.wxss

.navbar-container {width: 100%;position: relative;z-index: 999;
}.navbar {position: fixed;top: 0;left: 0;width: 100%;background: #fff;z-index: 999;box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
}.status-bar {width: 100%;background: #fff;
}.navbar-content {height: 44px;display: flex;align-items: center;padding: 0 12px;position: relative;background: #fff;
}.left {display: flex;align-items: center;min-width: 90px;position: relative;z-index: 2;
}.back-icon, .home-icon {padding: 6px;display: flex;align-items: center;justify-content: center;
}.back-icon .nav-icon {font-size: 50rpx;
}.home-icon .nav-icon {font-size: 40rpx;
}.icon-image {width: 24px;height: 24px;
}.center {flex: 1;text-align: center;font-size: 17px;font-weight: 500;color: #000;position: absolute;left: 0;right: 0;z-index: 1;height: 44px;line-height: 44px;
}.right {min-width: 90px;position: relative;z-index: 2;
}/* 导航栏占位元素 */
.navbar-placeholder {width: 100%;background: transparent;
}/* 为使用自定义导航栏的页面提供的全局样式类 */
.with-custom-navbar {padding-top: env(safe-area-inset-top);min-height: 100vh;box-sizing: border-box;background: #f5f5f5;
}/* 横屏模式样式 */
.navbar.landscape {position: fixed;top: 0;left: 0;width: 100vw;height: 44px;padding: 0;margin: 0;
}.navbar.landscape .status-bar {display: none;
}.navbar.landscape .navbar-content {height: 44px;padding: 0 8px;margin: 0;
}.navbar.landscape .back-icon .nav-icon {font-size: 32rpx;
}.navbar.landscape .home-icon .nav-icon {font-size: 28rpx;
}.navbar.landscape .center {font-size: 14px;height: 44px;line-height: 44px;
}.navbar.landscape .back-icon,
.navbar.landscape .home-icon {padding: 4px;
} 

custom-navbar.js

Component({properties: {// 标题title: {type: String,value: ''},// 是否显示返回按钮showBack: {type: Boolean,value: true},// 是否显示首页按钮showHome: {type: Boolean,value: true},// 首页路径homePath: {type: String,value: '/pages/index/index'}},data: {statusBarHeight: 0,isLandscape: false},lifetimes: {attached() {this.updateNavBarStatus();// 监听屏幕旋转wx.onWindowResize((res) => {const { windowWidth, windowHeight } = res.size;const newIsLandscape = windowWidth > windowHeight;if (this.data.isLandscape !== newIsLandscape) {// 延迟一下更新,确保系统信息已经更新setTimeout(() => {this.updateNavBarStatus();}, 100);}});},detached() {wx.offWindowResize();}},methods: {// 更新导航栏状态updateNavBarStatus() {try {const systemInfo = wx.getSystemInfoSync();const isLandscape = systemInfo.windowWidth > systemInfo.windowHeight;console.log('系统信息:', systemInfo);console.log('是否横屏:', isLandscape);console.log('状态栏高度:', systemInfo.statusBarHeight);this.setData({isLandscape: isLandscape,statusBarHeight: isLandscape ? 0 : (systemInfo.statusBarHeight || 48)});} catch (error) {console.error('获取系统信息失败:', error);// 设置默认值this.setData({statusBarHeight: 48});}},// 返回上一页onBack() {const pages = getCurrentPages();if (pages.length > 1) {wx.navigateBack();} else {wx.reLaunch({url: this.data.homePath});}this.triggerEvent('back');},// 返回首页onGoHome() {wx.reLaunch({url: '/pages/index/index',});this.triggerEvent('home');}}
}); 

custom-navbar.json

{"component": true,"usingComponents": {"t-navbar": "tdesign-miniprogram/navbar/navbar","t-icon": "tdesign-miniprogram/icon/icon"}
} 
http://www.mnyf.cn/news/36372.html

相关文章:

  • 公安局松江分局网站打开百度一下
  • 网站首页调用网站标题网页设计基础
  • 新手学做网站pdf5000元网站seo推广
  • 手机移动端网站建设宣传0元入驻的电商平台
  • 做网站常用的语言搜索软件使用排名
  • 网站开发 怎样做费用结算百度竞价排名是什么意思
  • 印度喜欢用什么框架做外贸网站百度一下百度首页官网
  • 珠海网站建设专线百度百科词条创建入口
  • 四川鸿业建设集团网站游戏推广怎么做挣钱
  • 静海网站建设公司国家免费职业培训平台
  • 湘潭做网站价格 d磐石网络关键词优化是什么意思
  • 325建筑网站德阳网站seo
  • 南京快速建站模板下载网站搜索引擎优化案例
  • 个旧做网站哪家公司好品牌网站建设哪家好
  • 想找个专业做网站公司seo舆情优化
  • 网站搭建好有什么内容可以修改如何做一个营销方案
  • 4s店网站建设品牌运营具体做什么
  • 机构改革后政府网站建设方案广州今天刚刚发生的重大新闻
  • wordpress的首页设置江苏网站seo设计
  • 通城做网站的今日重点新闻
  • 网站开发看谁的教程东莞推广平台有哪些
  • p2p贷款网站开发百度推广关键词怎么设置好
  • 德阳网站建设求职简历seo关键词优化报价
  • 海珠做网站东莞疫情最新消息通知
  • ps做网站页面先后顺序网站推广代理
  • 直播型网站开发免费换友情链接
  • nginx 做udp网站如何引流客源最快的方法
  • 西安公积金 网站建设百度关键词优化师
  • 手机电商网站 模板网店推广网站
  • 长沙网站建设招聘爱站网站