Browse Source

修复iOS系统搜索框隐藏时页面强行下滑和过渡动画不兼容问题

pull/1/head
Trae AI 2 months ago
parent
commit
b7d4224fd3
  1. 32
      pages/index/index.js
  2. 23
      pages/index/index.wxss

32
pages/index/index.js

@ -870,21 +870,30 @@ Page({
}); });
}, },
// 滚动事件处理 - 简化版本 // 滚动事件处理 - 简化并修复iOS兼容性问题
onScroll: function(e) { onScroll: function(e) {
const { scrollTop } = e.detail; const { scrollTop } = e.detail;
// 使用简单的阈值判断 // 使用更平滑的阈值判断,避免iOS上的抖动
const shouldHide = scrollTop > 100; const threshold = 100;
// 只有当状态需要改变时才更新 // 检查滚动方向
if (shouldHide !== this.data.isSearchBarFullyHidden) { const scrollingDown = scrollTop > this.data.lastScrollTop;
const scrollingUp = scrollTop < this.data.lastScrollTop;
// 只在滚动超过阈值且方向改变时才更新状态
if (scrollingDown && scrollTop > threshold && !this.data.isSearchBarFullyHidden) {
this.setData({ this.setData({
isSearchBarFullyHidden: shouldHide, isSearchBarFullyHidden: true,
lastScrollTop: scrollTop
});
} else if (scrollingUp && scrollTop <= threshold && this.data.isSearchBarFullyHidden) {
this.setData({
isSearchBarFullyHidden: false,
lastScrollTop: scrollTop lastScrollTop: scrollTop
}); });
} else { } else {
// 只更新滚动位置 // 其他情况只更新滚动位置
this.setData({ this.setData({
lastScrollTop: scrollTop lastScrollTop: scrollTop
}); });
@ -897,10 +906,15 @@ Page({
this.setData({ showBackToTop: false }); this.setData({ showBackToTop: false });
} }
const { scrollHeight, clientHeight } = e.detail;
const distanceToBottom = scrollHeight - scrollTop - clientHeight;
const app = getApp(); const app = getApp();
if (app && app.globalData) { if (!app || !app.globalData) {
app.globalData.showTabBar = true; return;
} }
app.globalData.showTabBar = true;
}, },
// 回到顶部 // 回到顶部

23
pages/index/index.wxss

@ -16,10 +16,10 @@ page {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
box-sizing: border-box; box-sizing: border-box;
/* 移除背景色,让page的背景渐变显示出来 */ background-color: #f8f8f8;
} }
/* 顶部搜索区域容器 - 保持紫色渐变背景 */ /* 为整个容器添加修复 */
.top-section-container { .top-section-container {
position: fixed; position: fixed;
top: 0; top: 0;
@ -29,8 +29,8 @@ page {
background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%); background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94); transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
transform: translateY(0); transform: translateY(0);
will-change: transform; will-change: transform; /* iOS性能优化 */
-webkit-transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94); -webkit-transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94); /* iOS兼容 */
} }
/* 隐藏时的状态 */ /* 隐藏时的状态 */
@ -82,17 +82,15 @@ page {
opacity: 0; opacity: 0;
} }
/* 商品列表区域 - 调整位置 */ /* 商品列表添加顶部内边距 */
.goods-section { .goods-list {
margin-top: 240rpx; /* 给搜索区域留出空间 */ padding-top: 240rpx; /* 与搜索区域高度匹配 */
height: calc(100vh - 240rpx); transition: padding-top 0.3s ease;
background: transparent; /* 透明背景,显示page的渐变 */
} }
/* 当搜索框隐藏时调整内边距 */ /* 当搜索框隐藏时调整内边距 */
.top-section-container.top-hidden ~ .goods-section { .top-section-container.top-hidden ~ .goods-list {
margin-top: 100rpx; padding-top: 100rpx; /* 减少内边距 */
height: calc(100vh - 100rpx);
} }
/* 品种筛选区域调整 */ /* 品种筛选区域调整 */
@ -132,6 +130,7 @@ page {
/* 确保滚动视图有正确的容器高度 */ /* 确保滚动视图有正确的容器高度 */
.goods-section { .goods-section {
height: 100vh;
position: relative; position: relative;
} }

Loading…
Cancel
Save