diff --git a/ScrollTabPageViewController.xcodeproj/project.pbxproj b/ScrollTabPageViewController.xcodeproj/project.pbxproj old mode 100644 new mode 100755 index af4e8f2..34f2e61 --- a/ScrollTabPageViewController.xcodeproj/project.pbxproj +++ b/ScrollTabPageViewController.xcodeproj/project.pbxproj @@ -271,10 +271,12 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = ScrollTabPageViewController/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = jp.vasily.ScrollTabPageViewController; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -282,10 +284,12 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = ScrollTabPageViewController/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = jp.vasily.ScrollTabPageViewController; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/ScrollTabPageViewController.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/ScrollTabPageViewController.xcodeproj/project.xcworkspace/contents.xcworkspacedata old mode 100644 new mode 100755 diff --git a/ScrollTabPageViewController/AppDelegate.swift b/ScrollTabPageViewController/AppDelegate.swift old mode 100644 new mode 100755 index 39b3b44..824bada --- a/ScrollTabPageViewController/AppDelegate.swift +++ b/ScrollTabPageViewController/AppDelegate.swift @@ -13,9 +13,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. return true } } - diff --git a/ScrollTabPageViewController/Assets.xcassets/AppIcon.appiconset/Contents.json b/ScrollTabPageViewController/Assets.xcassets/AppIcon.appiconset/Contents.json old mode 100644 new mode 100755 diff --git a/ScrollTabPageViewController/Classes/ContentsView.swift b/ScrollTabPageViewController/Classes/ContentsView.swift old mode 100644 new mode 100755 index 23f9ecd..05b406e --- a/ScrollTabPageViewController/Classes/ContentsView.swift +++ b/ScrollTabPageViewController/Classes/ContentsView.swift @@ -10,34 +10,36 @@ import UIKit class ContentsView: UIView { + // 選択されているtabボタンのindex var currentIndex: Int = 0 - var tabButtonPressedBlock: ((index: Int) -> Void)? - var scrollDidChangedBlock: ((scroll: CGFloat, shouldScroll: Bool) -> Void)? - - private var scrollStart: CGFloat = 0.0 - - @IBOutlet private weak var contentView: UIView! - @IBOutlet private weak var containerView: UIView! - @IBOutlet private weak var scrollView: UIScrollView! - @IBOutlet var tabButtons: [UIButton]! - + + var tabButtonPressedBlock: ((_ index: Int) -> Void)? + var scrollDidChangedBlock: ((_ scroll: CGFloat, _ shouldScroll: Bool) -> Void)? + + // スクロール開始時点の初期値 + var scrollStart: CGFloat = 0.0 + + @IBOutlet weak var contentView: UIView! + @IBOutlet weak var containerView: UIView! + @IBOutlet weak var scrollView: UIScrollView! + @IBOutlet weak var segmentedControl: UISegmentedControl! + @IBOutlet weak var segmentedControlHeight: NSLayoutConstraint! + let statusBarHeight: CGFloat = UIApplication.shared.statusBarFrame.height required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder)! - sharedInit() } override init(frame: CGRect) { super.init(frame: frame) - sharedInit() } private func sharedInit() { - NSBundle.mainBundle().loadNibNamed("ContentsView", owner: self, options: nil) + Bundle.main.loadNibNamed("ContentsView", owner: self, options: nil) addSubview(contentView) - setupConstraints() + self.setupConstraints() scrollView.delegate = self scrollView.scrollsToTop = false @@ -49,14 +51,15 @@ class ContentsView: UIView { extension ContentsView { - private func setupConstraints() { - let topConstraint = NSLayoutConstraint(item: contentView, attribute: .Top, relatedBy: .Equal, toItem: self, attribute: .Top, multiplier: 1.0, constant: 0.0) + // 制約を更新 + func setupConstraints() { + let topConstraint = NSLayoutConstraint(item: contentView, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1.0, constant: 20.0) - let bottomConstraint = NSLayoutConstraint(item: contentView, attribute: .Bottom, relatedBy: .Equal, toItem: self, attribute: .Bottom, multiplier: 1.0, constant: 0.0) + let bottomConstraint = NSLayoutConstraint(item: contentView, attribute: .bottom, relatedBy: .equal, toItem: self, attribute: .bottom, multiplier: 1.0, constant: 0.0) - let leftConstraint = NSLayoutConstraint(item: contentView, attribute: .Left, relatedBy: .Equal, toItem: self, attribute: .Left, multiplier: 1.0, constant: 0.0) + let leftConstraint = NSLayoutConstraint(item: contentView, attribute: .left, relatedBy: .equal, toItem: self, attribute: .left, multiplier: 1.0, constant: 0.0) - let rightConstraint = NSLayoutConstraint(item: contentView, attribute: .Right, relatedBy: .Equal, toItem: self, attribute: .Right, multiplier: 1.0, constant: 0.0) + let rightConstraint = NSLayoutConstraint(item: contentView, attribute: .right, relatedBy: .equal, toItem: self, attribute: .right, multiplier: 1.0, constant: 0.0) let constraints = [topConstraint, bottomConstraint, leftConstraint, rightConstraint] @@ -64,16 +67,24 @@ extension ContentsView { addConstraints(constraints) } - private func randomColor() -> UIColor { - let red = Float(arc4random_uniform(255)) / 255.0 - let green = Float(arc4random_uniform(255)) / 255.0 - let blue = Float(arc4random_uniform(255)) / 255.0 - return UIColor(colorLiteralRed: red, green: green, blue: blue, alpha: 1.0) + /** + ランダムな色を取得 + - returns: ランダムな色 + */ + func randomColor() -> UIColor { + let red = CGFloat(arc4random_uniform(255)) / 255.0 + let green = CGFloat(arc4random_uniform(255)) / 255.0 + let blue = CGFloat(arc4random_uniform(255)) / 255.0 + return UIColor(red: red, green: green, blue: blue, alpha: 1.0) } - + + /** + tabボタンのindex番号を更新 + - parameter index: 更新しようとしているindex番号 + - parameter animated: アニメーションするかのBOOL + */ func updateCurrentIndex(index: Int, animated: Bool) { - tabButtons[currentIndex].backgroundColor = UIColor.whiteColor() - tabButtons[index].backgroundColor = UIColor(red: 0.88, green: 1.0, blue: 0.87, alpha: 1.0) + segmentedControl.selectedSegmentIndex = index currentIndex = index } } @@ -83,13 +94,23 @@ extension ContentsView { extension ContentsView: UIScrollViewDelegate { - func scrollViewDidScroll(scrollView: UIScrollView) { - if scrollView.contentOffset.y > 0.0 || frame.minY < 0.0 { - scrollDidChangedBlock?(scroll: scrollView.contentOffset.y, shouldScroll: true) + /** + contentsViewへのスクロールを検知 + - parameter scrollView: scrollView + */ + func scrollViewDidScroll(_ scrollView: UIScrollView) { + if scrollView.contentOffset.y > statusBarHeight { + scrollDidChangedBlock?(scrollView.contentOffset.y, true) + scrollView.contentOffset.y = statusBarHeight + } else if scrollView.contentOffset.y > 0.0 { + scrollDidChangedBlock?(scrollView.contentOffset.y, true) + scrollView.contentOffset.y = 0.0 + } else if frame.minY < 0.0 { + scrollDidChangedBlock?(scrollView.contentOffset.y, true) scrollView.contentOffset.y = 0.0 } else { let scroll = scrollView.contentOffset.y - scrollStart - scrollDidChangedBlock?(scroll: scroll, shouldScroll: false) + scrollDidChangedBlock?(scroll, false) scrollStart = scrollView.contentOffset.y } } @@ -99,13 +120,11 @@ extension ContentsView: UIScrollViewDelegate { // MARK: - IBAction extension ContentsView { - - @IBAction private func touchButtonTouchUpInside(button: UIButton) { + @IBAction private func touchButtonTouchUpInside(_ sender: UIButton) { containerView.backgroundColor = randomColor() } - - @IBAction private func tabButtonTouchUpInside(button: UIButton) { - tabButtonPressedBlock?(index: button.tag) - updateCurrentIndex(button.tag, animated: true) + @IBAction func segmentValueChanged(_ sender: UISegmentedControl) { + tabButtonPressedBlock?(sender.selectedSegmentIndex) + updateCurrentIndex(index: sender.selectedSegmentIndex, animated: true) } } diff --git a/ScrollTabPageViewController/Classes/ContentsView.xib b/ScrollTabPageViewController/Classes/ContentsView.xib index 928a32a..6b43543 100644 --- a/ScrollTabPageViewController/Classes/ContentsView.xib +++ b/ScrollTabPageViewController/Classes/ContentsView.xib @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -10,32 +14,30 @@ - - + + - + - + - - + @@ -43,65 +45,34 @@ - - - - - - - - + + + - - - - - - - - - + - + + + + + + + + - - + - + - - + + - - - + + + - @@ -112,7 +83,7 @@ - + diff --git a/ScrollTabPageViewController/Classes/ScrollTabPageViewController.swift b/ScrollTabPageViewController/Classes/ScrollTabPageViewController.swift old mode 100644 new mode 100755 index b72d846..46cd9c7 --- a/ScrollTabPageViewController/Classes/ScrollTabPageViewController.swift +++ b/ScrollTabPageViewController/Classes/ScrollTabPageViewController.swift @@ -15,16 +15,27 @@ protocol ScrollTabPageViewControllerProtocol { class ScrollTabPageViewController: UIPageViewController { - private let contentViewHeihgt: CGFloat = 280.0 - private let tabViewHeight: CGFloat = 44.0 - private var pageViewControllers: [UIViewController] = [] - private var contentsView: ContentsView! - private var scrollContentOffsetY: CGFloat = 0.0 - private var shouldScrollFrame: Bool = true - private var shouldUpdateLayout: Bool = false - private var updateIndex: Int = 0 - private var currentIndex: Int? { - guard let viewController = viewControllers?.first, index = pageViewControllers.indexOf(viewController) else { + var pageViewControllers: [UIViewController] = [] + + // pageViewControllerの更新index + var updateIndex: Int = 0 + + var contentsView: ContentsView! + + // contentViewの高さ + let contentViewHeihgt: CGFloat = 280.0 + + // contentsViewのスクロールの値 + var scrollContentOffsetY: CGFloat = 0.0 + + var shouldScrollFrame: Bool = true + var shouldUpdateLayout: Bool = false + let statusBarHeight: CGFloat = UIApplication.shared.statusBarFrame.height + + + // tabViewControllerの現在のindex + var currentIndex: Int? { + guard let viewController = viewControllers?.first, let index = pageViewControllers.index(of: viewController) else { return nil } return index @@ -32,8 +43,7 @@ class ScrollTabPageViewController: UIPageViewController { override func viewDidLoad() { super.viewDidLoad() - - setupOutlets() + self.setupOutlets() } } @@ -42,36 +52,45 @@ class ScrollTabPageViewController: UIPageViewController { extension ScrollTabPageViewController { - private func setupOutlets() { + // outletをセットアップ + func setupOutlets() { setupViewControllers() setupContentsView() setupPageViewController() } - private func setupViewControllers() { + // viewControllerをセットアップ + // 別々のviewControllerを設定する場合はvc1&2の読み込み内容を変更する + func setupViewControllers() { + // viewContrroller let sb1 = UIStoryboard(name: "ViewController", bundle: nil) - let vc1 = sb1.instantiateViewControllerWithIdentifier("ViewController") + let vc1 = sb1.instantiateViewController(withIdentifier: "ViewController") + // viewContrroller let sb2 = UIStoryboard(name: "ViewController", bundle: nil) - let vc2 = sb2.instantiateViewControllerWithIdentifier("ViewController") + let vc2 = sb2.instantiateViewController(withIdentifier: "ViewController") pageViewControllers = [vc1, vc2] } - private func setupPageViewController() { + // pageViewControllerをセットアップする + func setupPageViewController() { dataSource = self delegate = self + // 初回表示のviewControllerをセット setViewControllers([pageViewControllers[0]], - direction: .Forward, + direction: .forward, animated: false, completion: { [weak self] (completed: Bool) in - self?.setupContentInset() + self?.setupCurrentContentInset() }) } - private func setupContentsView() { - contentsView = ContentsView(frame: CGRectMake(0.0, 0.0, view.frame.width, contentViewHeihgt)) + // contentsViewのセットアップ + func setupContentsView() { + contentsView = ContentsView(frame: CGRect(x:0.0, y:0.0, width:view.frame.width, height:contentViewHeihgt)) + // タブボタンがタップされた時のブロック contentsView.tabButtonPressedBlock = { [weak self] (index: Int) in guard let uself = self else { return @@ -79,7 +98,7 @@ extension ScrollTabPageViewController { uself.shouldUpdateLayout = true uself.updateIndex = index - let direction: UIPageViewControllerNavigationDirection = (uself.currentIndex < index) ? .Forward : .Reverse + let direction: UIPageViewControllerNavigationDirection = (uself.currentIndex! < index) ? .forward : .reverse uself.setViewControllers([uself.pageViewControllers[index]], direction: direction, animated: true, @@ -88,15 +107,17 @@ extension ScrollTabPageViewController { return } if uself.shouldUpdateLayout { - uself.setupContentOffsetY(index, scroll: -uself.scrollContentOffsetY) + uself.setupContentOffsetY(index:index, scroll: -uself.scrollContentOffsetY) uself.shouldUpdateLayout = false } }) } + // contentViewのスクロール表示が変更された時のブロック contentsView.scrollDidChangedBlock = { [weak self] (scroll: CGFloat, shouldScrollFrame: Bool) in self?.shouldScrollFrame = shouldScrollFrame - self?.updateContentOffsetY(scroll) + // Y座標を更新する + self?.updateContentOffsetY(scroll: scroll) } view.addSubview(contentsView) } @@ -107,29 +128,52 @@ extension ScrollTabPageViewController { extension ScrollTabPageViewController { - private func setupContentInset() { - guard let currentIndex = currentIndex, vc = pageViewControllers[currentIndex] as? ScrollTabPageViewControllerProtocol else { + /** + 現在のscrollViewのcontentInsetをセット + */ + func setupCurrentContentInset() { + guard let currentIndex = currentIndex, let vc = pageViewControllers[currentIndex] as? ScrollTabPageViewControllerProtocol else { return } - let inset = UIEdgeInsetsMake(contentViewHeihgt, 0.0, 0.0, 0.0) - vc.scrollView.contentInset = inset - vc.scrollView.scrollIndicatorInsets = inset + vc.scrollView.contentInset.top = contentViewHeihgt + vc.scrollView.scrollIndicatorInsets.top = contentViewHeihgt + } + + /** + 次のscrollViewのcontentInsetをセット + */ + func setupNextContentInset(nextIndex:Int) { + guard let vc = pageViewControllers[nextIndex] as? ScrollTabPageViewControllerProtocol else { + return + } + + vc.scrollView.contentInset.top = contentViewHeihgt + vc.scrollView.scrollIndicatorInsets.top = contentViewHeihgt } - private func setupContentOffsetY(index: Int, scroll: CGFloat) { + /** + Y座標をセット(初期表示やページングがされた時) + - parameter index: ページングのindex + - parameter scroll: どれだけスクロールしているか + */ + func setupContentOffsetY(index: Int, scroll: CGFloat) { guard let vc = pageViewControllers[index] as? ScrollTabPageViewControllerProtocol else { return } if scroll == 0.0 { vc.scrollView.contentOffset.y = -contentViewHeihgt - } else if (scroll < contentViewHeihgt - tabViewHeight) || (vc.scrollView.contentOffset.y <= -tabViewHeight) { + } else if (scroll < contentViewHeihgt - contentsView.segmentedControlHeight.constant) || (vc.scrollView.contentOffset.y <= -contentsView.segmentedControlHeight.constant) { vc.scrollView.contentOffset.y = scroll - contentViewHeihgt } } - private func updateContentView(scroll: CGFloat) { + /** + viewControllerのスクロールでのcontentViewを更新 + - parameter scroll: 移動した分の座標 + */ + func updateContentView(scroll: CGFloat) { if shouldScrollFrame { contentsView.frame.origin.y = scroll scrollContentOffsetY = scroll @@ -137,24 +181,32 @@ extension ScrollTabPageViewController { shouldScrollFrame = true } - private func updateContentOffsetY(scroll: CGFloat) { - if let currentIndex = currentIndex, vc = pageViewControllers[currentIndex] as? ScrollTabPageViewControllerProtocol { + /** + Y座標を更新 + - parameter scroll: 移動した分の座標 + */ + func updateContentOffsetY(scroll: CGFloat) { + if let currentIndex = currentIndex, let vc = pageViewControllers[currentIndex] as? ScrollTabPageViewControllerProtocol { vc.scrollView.contentOffset.y += scroll } } func updateContentViewFrame() { - guard let currentIndex = currentIndex, vc = pageViewControllers[currentIndex] as? ScrollTabPageViewControllerProtocol else { + guard let currentIndex = currentIndex, let vc = pageViewControllers[currentIndex] as? ScrollTabPageViewControllerProtocol else { return } - if vc.scrollView.contentOffset.y >= -tabViewHeight { - let scroll = contentViewHeihgt - tabViewHeight - updateContentView(-scroll) - vc.scrollView.scrollIndicatorInsets.top = tabViewHeight + // 予めスクロールのcontentOffsetはcontentsViewの分だけ差し引かれている。 + // スクロールの長さがsegmentedControlの高さより大きいかどうか判定 + if vc.scrollView.contentOffset.y >= -contentsView.segmentedControlHeight.constant { + // tableViewのスクロール更新 + let scroll = contentViewHeihgt - contentsView.segmentedControlHeight.constant + updateContentView(scroll: -scroll) + vc.scrollView.scrollIndicatorInsets.top = contentsView.segmentedControlHeight.constant } else { + // contentsViewとtableViewのスクロール更新 let scroll = contentViewHeihgt + vc.scrollView.contentOffset.y - updateContentView(-scroll) + updateContentView(scroll: -scroll) vc.scrollView.scrollIndicatorInsets.top = -vc.scrollView.contentOffset.y } } @@ -164,9 +216,8 @@ extension ScrollTabPageViewController { let vc = pageViewControllers[updateIndex] as? ScrollTabPageViewControllerProtocol let shouldSetupContentOffsetY = vc?.scrollView.contentInset.top != contentViewHeihgt - let scroll = scrollContentOffsetY - setupContentInset() - setupContentOffsetY(updateIndex, scroll: -scroll) + setupCurrentContentInset() + setupContentOffsetY(index: updateIndex, scroll: -scrollContentOffsetY) shouldUpdateLayout = shouldSetupContentOffsetY } } @@ -177,27 +228,39 @@ extension ScrollTabPageViewController { extension ScrollTabPageViewController: UIPageViewControllerDataSource { - func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? { - - guard var index = pageViewControllers.indexOf(viewController) else { + /** + 1つ目のviewControllerに戻った時の処理 + - parameter pageViewController: pageViewController + - parameter viewController: 現在表示されている2つ目のviewController + - returns: 1つ目に戻った時に表示されるviewController + */ + func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? { + + guard var index = pageViewControllers.index(of: viewController) else { + return nil + } + + index = index - 1 + + if index >= 0 && index < pageViewControllers.count { + return pageViewControllers[index] + } return nil - } - - index++ - - if index >= 0 && index < pageViewControllers.count { - return pageViewControllers[index] - } - return nil } - - func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? { - - guard var index = pageViewControllers.indexOf(viewController) else { + + /** + 2つ目のviewControllerに進んだ時の処理 + - parameter pageViewController: pageViewController + - parameter viewController: 現在表示されている1つ目のviewController + - returns: 2つ目に進んだ時に表示されるviewController + */ + func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? { + + guard var index = pageViewControllers.index(of: viewController) else { return nil } - index-- + index = index + 1 if index >= 0 && index < pageViewControllers.count { return pageViewControllers[index] @@ -211,26 +274,38 @@ extension ScrollTabPageViewController: UIPageViewControllerDataSource { extension ScrollTabPageViewController: UIPageViewControllerDelegate { - func pageViewController(pageViewController: UIPageViewController, willTransitionToViewControllers pendingViewControllers: [UIViewController]) { - if let vc = pendingViewControllers.first, index = pageViewControllers.indexOf(vc) { + /** + スワイプでpageViewControllerで別のviewControllerに遷移する時の処理 + - parameter pageViewController: pageViewController + - parameter pagingViewControllers: これから遷移しようとしているviewController + */ + func pageViewController(_ pageViewController: UIPageViewController, willTransitionTo pendingViewControllers: [UIViewController]) { + if let vc = pendingViewControllers.first, let index = pageViewControllers.index(of: vc) { shouldUpdateLayout = true updateIndex = index + setupNextContentInset(nextIndex: updateIndex) } - } - func pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) { - guard let _ = previousViewControllers.first, currentIndex = currentIndex else { + /** + pageViewControllerのアニメーションが終わった時の処理 + - parameter pageViewController: pageViewController + - parameter fisnished: アニメーション完了のBOOL値 + - parameter previousViewControllers: 遷移前のviewController + - parameter completed: 遷移完了のBOOL値 + */ + func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) { + guard let _ = previousViewControllers.first, let currentIndex = currentIndex else { return } if shouldUpdateLayout { - setupContentInset() - setupContentOffsetY(currentIndex, scroll: -scrollContentOffsetY) + setupCurrentContentInset() + setupContentOffsetY(index: currentIndex, scroll: -scrollContentOffsetY) } - if currentIndex >= 0 && currentIndex < contentsView.tabButtons.count { - contentsView.updateCurrentIndex(currentIndex, animated: false) + if currentIndex >= 0 && currentIndex < contentsView.segmentedControl.numberOfSegments { + contentsView.updateCurrentIndex(index: currentIndex, animated: false) } } } diff --git a/ScrollTabPageViewController/Classes/ViewController.storyboard b/ScrollTabPageViewController/Classes/ViewController.storyboard index 6380e7e..3c3f676 100644 --- a/ScrollTabPageViewController/Classes/ViewController.storyboard +++ b/ScrollTabPageViewController/Classes/ViewController.storyboard @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -14,19 +18,17 @@ - + - - - + + - - + - + diff --git a/ScrollTabPageViewController/Classes/ViewController.swift b/ScrollTabPageViewController/Classes/ViewController.swift old mode 100644 new mode 100755 index 082a3c8..75101d7 --- a/ScrollTabPageViewController/Classes/ViewController.swift +++ b/ScrollTabPageViewController/Classes/ViewController.swift @@ -10,7 +10,7 @@ import UIKit class ViewController: UIViewController { - @IBOutlet private weak var tableView: UITableView! + @IBOutlet weak var tableView: UITableView! override func viewDidLoad() { super.viewDidLoad() @@ -20,9 +20,8 @@ class ViewController: UIViewController { } - override func viewWillAppear(animated: Bool) { + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - scrollTabPageViewController.updateLayoutIfNeeded() } } @@ -32,12 +31,12 @@ class ViewController: UIViewController { extension ViewController: UITableViewDataSource { - func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 100 } - func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - let cell = UITableViewCell(style: .Subtitle, reuseIdentifier: "Cell") + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "Cell") cell.textLabel?.text = String(indexPath.row) return cell } @@ -47,8 +46,12 @@ extension ViewController: UITableViewDataSource { // MARK: - UIScrollViewDelegate extension ViewController: UITableViewDelegate { - - func scrollViewDidScroll(scrollView: UIScrollView) { + /** + viewControllerへのスクロールを検知 + - parameter scrollView: scrollView + */ + func scrollViewDidScroll(_ scrollView: UIScrollView) { + // contentsViewのスクロールを同期 scrollTabPageViewController.updateContentViewFrame() } } @@ -59,7 +62,7 @@ extension ViewController: UITableViewDelegate { extension ViewController: ScrollTabPageViewControllerProtocol { var scrollTabPageViewController: ScrollTabPageViewController { - return parentViewController as! ScrollTabPageViewController + return parent as! ScrollTabPageViewController } var scrollView: UIScrollView { diff --git a/ScrollTabPageViewController/Info.plist b/ScrollTabPageViewController/Info.plist old mode 100644 new mode 100755