swiftのTabPageViewControllerのcurrent_indexを取得したいです
TabPageViewController公式ページ
https://github.com/EndouMari/TabPageViewController
前回こちらで質問したこと
https://teratail.com/questions/44158
(swiftのTabPageViewControllerの上部タブの高さをTableView上下スクロール時に変更したい)
を皆さんのおかげで解決できたのですが、
上部タブの高さを小さくしたところ
tabItems内のViewContorollerのtableViewのAutoLayoutのtop部分も再調整する必要がでてきました。
そこで現在のTabのindex値を取得して現在表示しているViewControllerのAutolayoutを
調整したいので、できるかやってみたところ
最初のviewControllerのAutolayoutは以下のようなコードで変更できました。
(以下のtabItems[0]の部分が最初のviewController)
swift
1class CustomTabPageViewController: TabPageViewController { 2 func setMarginTop(margin: CGFloat) { 3 let vc: ListViewController = tabItems[0].viewController as! ListViewController 4 vc.setMarginTop(margin) 5 } 6 7class ListViewController: UIViewController ,UITableViewDataSource, UITableViewDelegate { 8 func setMarginTop(margin: CGFloat) { 9 // 自動レイアウトoff 10 self.imgTableView.translatesAutoresizingMaskIntoConstraints = false 11 self.view.removeConstraint(_view1MarginTop) 12 // 自動レイアウトtop 13 _view1MarginTop = NSLayoutConstraint( 14 item: imgTableView, 15 attribute: NSLayoutAttribute.Top, 16 relatedBy: NSLayoutRelation.Equal, 17 toItem: self.topLayoutGuide, 18 attribute: NSLayoutAttribute.Top, 19 multiplier: 1.0, 20 constant: margin) 21 self.view.addConstraint(_view1MarginTop) 22 } 23
あとは現在のindex値をtabItems[0]の0の部分にいれるだけなのですが、
index値がTabView.swiftのbeforeIndexに入っているっぽいのですがprivateで取得できずでした。
TabView.swiftは以下の通りです
swift
1internal class TabView: UIView { 2 3 var pageItemPressedBlock: ((index: Int, direction: UIPageViewControllerNavigationDirection) -> Void)? 4 var pageTabItems: [String] = [] { 5 didSet { 6 pageTabItemsCount = pageTabItems.count 7 beforeIndex = pageTabItems.count 8 } 9 } 10 11 private var isInfinity: Bool = false 12 private var option: TabPageOption = TabPageOption() 13 private var beforeIndex: Int = 0 14 private var currentIndex: Int = 0 15 private var pageTabItemsCount: Int = 0 16 private var shouldScrollToItem: Bool = false 17 private var pageTabItemsWidth: CGFloat = 0.0 18 private var collectionViewContentOffsetX: CGFloat = 0.0 19 private var currentBarViewWidth: CGFloat = 0.0 20 private var cellForSize: TabCollectionCell! 21 private var cachedCellSizes: [NSIndexPath: CGSize] = [:] 22 private var currentBarViewLeftConstraint: NSLayoutConstraint? 23
publicであれば以下で取得できるはずなのですが、privateなので取得できない感じです。
swift
1 if let tabView = view.subviews.last { 2 print(tabView.beforeIndex) 3 }
前回教えてもらった
swift
1view.subviews.last 2constraints.last
を駆使してどうにかできないかいろいろ試しましたが、
index値が他のviewに入ってなかったので取得できずでした。
どうにかindex値を取得できませんでしょうか?
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/08/15 10:13
2016/08/15 11:17
2016/08/15 12:11 編集
2016/08/15 15:21
2016/08/15 19:36 編集
2016/08/16 00:38 編集
2016/08/16 15:10