SwiftUI PageTabView in iOS14.2 will Recall ChildView onAppear method Many times

前端 未结 3 1582
轮回少年
轮回少年 2021-01-23 23:41

I use TabView PageTabViewStyle with SwiftUI to display a pageview, when I swipe this TabView I find child view will Recall onAppear method Many times, Can someone tell me why?

3条回答
  •  长情又很酷
    2021-01-23 23:52

    For everyone who is still struggling to find a good workaround for this problem. I've managed to use this framework https://github.com/fermoya/SwiftUIPager which can be used to mimic the TabView .tabViewStyle(PageTabViewStyle()) style.

    import SwiftUIPager
    struct Dummy: View {
        @StateObject var page: Page = .first()
        let numberOfPages : Int = 3
        var body: some View {
            
            Pager(page: self.page,
                  data: Array(0..

提交回复
热议问题