iOS 开发实用技术导航
NSHipster 中文版
› http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
› http://www.cocos2d-iphone.org/
CocoaPods
› http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
› http://code.google.com/mobile/analytics/
WWDC
› https://developer.apple.com/wwdc/
Design Guides and Resources
› https://developer.apple.com/design/
Transcripts of WWDC sessions
› http://asciiwwdc.com
Cocoa with Love
› http://cocoawithlove.com/
Cocoa Dev Central
› http://cocoadevcentral.com/
NSHipster
› http://nshipster.com/
Style Guides
› Google Objective-C Style Guide
› NYTimes Objective-C Style Guide
Useful Tools and Services
› Charles Web Debugging Proxy
› Smore
Windy418
V2EX  ›  iDev

在切换 Tab 时或通过 NavigationLink 进入子视图时,如何能记住 ScrollView 之前的滚动位置

  •  
  •   Windy418 · Mar 4, 2025 · 2240 views
    This topic created in 578 days ago, the information mentioned may be changed or developed.
    顶部有两个 tab ,可以切换,用的 SegmentedPickerStyle
    下面是一个 ScrollView ,用 LazyVGrid 放了一些卡片样式的数据
    比如,当左侧的 tab 的视图滑到第四行 card 的某个位置时,切换到第二个 tab ,然后再切回来,它就会自动回到第一行
    如何能让它记住我之前滑动到的地方,使得我每次切换 tab ,都可以保持上一次的位置继续向下浏览
    有没有大佬知道?

    这个问题在我在一个 ScrollView 视图中,使用 NavigationLink 进入子视图,再返回时,也会遇到,有时候位置会发生变化
    4 replies  •  2025-03-05 17:21:24 +08:00
    iOCZS
        1
    iOCZS  
       Mar 4, 2025
    最好是有简单的 demo 可以复现,一般来说,避免视图重建可以解决滚动位置丢失的问题
    okakuyang
        2
    okakuyang  
       Mar 4, 2025
    理论上不会出现这种情况,如果非要实现需求,可以记录滚动坐标,视图倒退的时候自动给它无动画模式滚到指定坐标
    Bananana
        3
    Bananana  
       Mar 5, 2025
    印象里不会重置滚动位置的,有代码发出来看看么
    Windy418
        4
    Windy418  
    OP
       Mar 5, 2025
    我好像发现问题原因了,之前我的代码套嵌
    是这样的:ScrollView -> ForEach -> Vstack -> Text, LazyVGrid
    我改成了:ScorllView -> LazyVGrid -> Section -> ForEach, header
    好像就没有这个问题了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2418 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:47 · PVG 20:47 · LAX 05:47 · JFK 08:47
    ♥ Do have faith in what you're doing.