Browse Source

修复苹果手机上按钮消失问题

- 初始化时校验保存的位置是否在有效范围内
- 确保默认位置始终在边界内 (20%~60%)
pull/1/head
徐飞洋 2 months ago
parent
commit
c37bb69dc5
  1. 20
      pages/index/index.js

20
pages/index/index.js

@ -150,18 +150,10 @@ Page({
const systemInfo = wx.getSystemInfoSync(); const systemInfo = wx.getSystemInfoSync();
const screenHeight = systemInfo.screenHeight * 2; const screenHeight = systemInfo.screenHeight * 2;
const safeArea = systemInfo.safeArea;
const btnHeight = 90; const btnHeight = 90;
let minTop, maxTop; const minTop = screenHeight * 0.2;
const maxTop = screenHeight * 0.6;
if (safeArea && safeArea.top > 20) {
minTop = safeArea.top * 2 + 20;
maxTop = safeArea.bottom * 2 - btnHeight - 20;
} else {
minTop = screenHeight * 0.2;
maxTop = screenHeight * 0.6;
}
if (newTop < minTop) { if (newTop < minTop) {
newTop = minTop; newTop = minTop;
@ -206,9 +198,13 @@ Page({
const systemInfo = wx.getSystemInfoSync(); const systemInfo = wx.getSystemInfoSync();
const screenHeight = systemInfo.screenHeight * 2; const screenHeight = systemInfo.screenHeight * 2;
let defaultTop = screenHeight / 2; let defaultTop = screenHeight * 0.5;
if (savedBtnTop !== '' && savedBtnTop !== -100) { if (savedBtnTop !== '' && savedBtnTop !== -100) {
defaultTop = savedBtnTop; const minTop = screenHeight * 0.2;
const maxTop = screenHeight * 0.6;
if (savedBtnTop >= minTop && savedBtnTop <= maxTop) {
defaultTop = savedBtnTop;
}
} }
this.setData({ this.setData({

Loading…
Cancel
Save