PageMenu / PageMenu

A paging menu controller built from other view controllers placed inside a scroll view (like Spotify, Windows Phone, Instagram)
BSD 3-Clause "New" or "Revised" License
5.27k stars 900 forks source link

self.addChild(pageMenuController!)。Method 'viewDidAppear' in the childviewcontroller is executed twice #516

Open LCBbest opened 3 years ago

LCBbest commented 3 years ago

if add this code self.addChild(pageMenuController!)。Method 'viewDidAppear' in the childviewcontroller is executed twice。How to solve it

code

  self.addChild(pageMenuController!)
  self.view.addSubview(pageMenuController!.view)
  pageMenuController!.didMove(toParent: self)

childcontroller

override func viewDidAppear(_ animated: Bool) {
     //executed twice
      print("hello")
}
vudinhdjv commented 3 years ago

I see that in file CAPSPageMenu+UIConfiguration.swift line 165 -> 170

if index == 0.0 {
    // Add first two controllers to scrollview and as child view controller
    controller.viewWillAppear(true)
    addPageAtIndex(0)
    controller.viewDidAppear(true)
    }

controller call viewWillAppear(true) and viewDidAppear(true). They also will be called when controller loaded. so that is reason why method viewDidAppear is executed twice. I don't know why we need to call two function in file CAPSPageMenu+UIConfiguration.swift .