Skip to content

Commit

Permalink
Merge pull request #57 from kazuhiro4949/feature/fix_reloadTiming
Browse files Browse the repository at this point in the history
fix layout bug in landscape mode
  • Loading branch information
kazuhiro4949 authored May 26, 2018
2 parents 5bf9b3d + 9073b07 commit 63fe576
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 4 additions & 1 deletion PagingKit/PagingMenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -247,6 +247,9 @@ public class PagingMenuViewController: UIViewController {
}
)
}

view.setNeedsLayout()
view.layoutIfNeeded()
}

/// Invalidates the current layout using the information in the provided context object.
Expand Down
14 changes: 11 additions & 3 deletions iOS Sample/iOS Sample/IndicatorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}

Expand All @@ -42,6 +45,11 @@ class IndicatorViewController: UIViewController {
// Dispose of any resources that can be recreated.
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
firstLoad?()
}


// MARK: - Navigation

Expand Down
1 change: 0 additions & 1 deletion iOS Sample/iOS Sample/SimpleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class SimpleViewController: UIViewController {

menuViewController?.register(type: TitleLabelMenuViewCell.self, forCellWithReuseIdentifier: "identifier")
menuViewController?.registerFocusView(view: UnderlineFocusView())

}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
Expand Down

0 comments on commit 63fe576

Please sign in to comment.