From 66d3e117e25b4d469e68a4e26b47429f378c53a4 Mon Sep 17 00:00:00 2001 From: Kazuhiro Hayashi Date: Sat, 26 May 2018 17:55:20 +0900 Subject: [PATCH 1/2] fix --- PagingKit/PagingMenuViewController.swift | 5 ++++- .../iOS Sample/IndicatorViewController.swift | 14 +++++++++++--- iOS Sample/iOS Sample/SimpleViewController.swift | 3 +++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/PagingKit/PagingMenuViewController.swift b/PagingKit/PagingMenuViewController.swift index 5d6d3d5..092aca3 100644 --- a/PagingKit/PagingMenuViewController.swift +++ b/PagingKit/PagingMenuViewController.swift @@ -236,8 +236,8 @@ public class PagingMenuViewController: UIViewController { let selectedIndex = preferredFocusIndex ?? currentFocusedIndex ?? 0 menuView.focusView.selectedIndex = selectedIndex menuView.contentOffset = .zero - menuView.reloadData() fireInvalidateLayout = { [weak self] in + self?.menuView.reloadData() UIView.pk.catchLayoutCompletion( layout: { [weak self] in self?.scroll(index: selectedIndex, percent: 0, animated: false) @@ -247,6 +247,9 @@ public class PagingMenuViewController: UIViewController { } ) } + + view.setNeedsLayout() + view.layoutIfNeeded() } /// Invalidates the current layout using the information in the provided context object. diff --git a/iOS Sample/iOS Sample/IndicatorViewController.swift b/iOS Sample/iOS Sample/IndicatorViewController.swift index d13e0e3..7af563d 100644 --- a/iOS Sample/iOS Sample/IndicatorViewController.swift +++ b/iOS Sample/iOS Sample/IndicatorViewController.swift @@ -26,14 +26,17 @@ class IndicatorViewController: UIViewController { }() ] + lazy var firstLoad: (() -> Void)? = { [weak self, menuViewController, contentViewController] in + menuViewController?.reloadData() + contentViewController?.reloadData() + self?.firstLoad = nil + } + override func viewDidLoad() { super.viewDidLoad() menuViewController?.registerFocusView(nib: UINib(nibName: "IndicatorFocusMenuView", bundle: nil)) menuViewController?.register(type: PagingMenuViewCell.self, forCellWithReuseIdentifier: "identifier") - - menuViewController?.reloadData() - contentViewController?.reloadData() // Do any additional setup after loading the view. } @@ -42,6 +45,11 @@ class IndicatorViewController: UIViewController { // Dispose of any resources that can be recreated. } + override func viewDidLayoutSubviews() { + super.viewDidLayoutSubviews() + firstLoad?() + } + // MARK: - Navigation diff --git a/iOS Sample/iOS Sample/SimpleViewController.swift b/iOS Sample/iOS Sample/SimpleViewController.swift index dfc1a16..b4627eb 100644 --- a/iOS Sample/iOS Sample/SimpleViewController.swift +++ b/iOS Sample/iOS Sample/SimpleViewController.swift @@ -48,6 +48,9 @@ class SimpleViewController: UIViewController { menuViewController?.register(type: TitleLabelMenuViewCell.self, forCellWithReuseIdentifier: "identifier") menuViewController?.registerFocusView(view: UnderlineFocusView()) + + menuViewController?.reloadData() + contentViewController?.reloadData() } override func viewDidLayoutSubviews() { From 9073b0700f9843189d774050f72eab23b2af8cb8 Mon Sep 17 00:00:00 2001 From: Kazuhiro Hayashi Date: Sat, 26 May 2018 18:38:03 +0900 Subject: [PATCH 2/2] fix reloadData() --- iOS Sample/iOS Sample/SimpleViewController.swift | 4 ---- 1 file changed, 4 deletions(-) diff --git a/iOS Sample/iOS Sample/SimpleViewController.swift b/iOS Sample/iOS Sample/SimpleViewController.swift index b4627eb..2067858 100644 --- a/iOS Sample/iOS Sample/SimpleViewController.swift +++ b/iOS Sample/iOS Sample/SimpleViewController.swift @@ -48,10 +48,6 @@ class SimpleViewController: UIViewController { menuViewController?.register(type: TitleLabelMenuViewCell.self, forCellWithReuseIdentifier: "identifier") menuViewController?.registerFocusView(view: UnderlineFocusView()) - - menuViewController?.reloadData() - contentViewController?.reloadData() - } override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews()