Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0
5.0
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# 0.2.9 Release notes (2019-10-10)

## Enhancements

Updated Swift Version from 4.2 to 5, and Deployment Target form 10.3 to 11.0.
Supported Safe Area Guide.

# 0.2.8 Release notes (2018-09-11)

## Enhancements

* Fixed Swift 4.2 warnings and updated deployment target to 10.3.

# 0.2.7 Release notes (2017-04-13)

## Enhancements
Expand Down
2 changes: 1 addition & 1 deletion Demo/TabPageViewControllerDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
Expand Down
19 changes: 8 additions & 11 deletions Demo/TabPageViewControllerDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="uo0-N0-NdD">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15400" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="uo0-N0-NdD">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15404"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="TabPageViewControllerDemo" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand All @@ -42,9 +37,10 @@
<constraints>
<constraint firstItem="K6D-9d-SQb" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="GWv-7J-MT8"/>
<constraint firstItem="aS6-Yk-eFK" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="fED-rw-YGl"/>
<constraint firstItem="aS6-Yk-eFK" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" constant="-50" id="ic2-Pv-vR0"/>
<constraint firstItem="aS6-Yk-eFK" firstAttribute="centerX" secondItem="qt1-1c-p6m" secondAttribute="centerX" constant="-50" id="ic2-Pv-vR0"/>
<constraint firstItem="K6D-9d-SQb" firstAttribute="leading" secondItem="aS6-Yk-eFK" secondAttribute="trailing" constant="50" id="rdP-Rj-9wB"/>
</constraints>
<viewLayoutGuide key="safeArea" id="qt1-1c-p6m"/>
</view>
<navigationItem key="navigationItem" id="1LR-hg-pDk"/>
</viewController>
Expand Down Expand Up @@ -78,12 +74,13 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="uRZ-WL-ioa"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" id="t9w-Bv-ukp">
<rect key="frame" x="0.0" y="28" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="t9w-Bv-ukp" id="t6B-aT-7Wi">
<rect key="frame" x="0.0" y="0.0" width="375" height="43"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
Expand Down
11 changes: 4 additions & 7 deletions Demo/TabPageViewControllerDemo/ListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ import UIKit
import TabPageViewController

class ListViewController: UITableViewController {

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

let navigationHeight = topLayoutGuide.length
tableView.contentInset.top = navigationHeight + TabPageOption().tabHeight

override func viewDidLoad() {
super.viewDidLoad()
tableView.contentInset.top = TabPageOption().tabHeight
}

fileprivate func updateNavigationBarOrigin(velocity: CGPoint) {
guard let tabPageViewController = parent as? TabPageViewController else { return }

if velocity.y > 0.5 {
tabPageViewController.updateNavigationBarHidden(true, animated: true)
} else if velocity.y < -0.5 {
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ tabPageViewController.isInfinity = true

## Requirements

iOS8+
iOS11.0+

## Installation

Expand All @@ -128,7 +128,7 @@ Copy all the files in `Pod/Classes` directory into your project.

## Author

EndouMari, endo@vasily.jp
EndouMari

## License

Expand Down
4 changes: 2 additions & 2 deletions Sources/TabCollectionCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

class TabCollectionCell: UICollectionViewCell {

var tabItemButtonPressedBlock: ((Void) -> Void)?
var tabItemButtonPressedBlock: (() -> Void)?
var option: TabPageOption = TabPageOption() {
didSet {
currentBarViewHeightConstraint.constant = option.currentBarHeight
Expand Down Expand Up @@ -47,7 +47,7 @@ class TabCollectionCell: UICollectionViewCell {
}

override func sizeThatFits(_ size: CGSize) -> CGSize {
if item.characters.count == 0 {
if item.count == 0 {
return CGSize.zero
}

Expand Down
111 changes: 26 additions & 85 deletions Sources/TabPageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ open class TabPageViewController: UIPageViewController {
guard let viewController = viewControllers?.first else {
return nil
}
return tabItems.map{ $0.viewController }.index(of: viewController)
return tabItems.map{ $0.viewController }.firstIndex(of: viewController)
}
fileprivate var beforeIndex: Int = 0
fileprivate var tabItemsCount: Int {
Expand Down Expand Up @@ -78,9 +78,9 @@ open class TabPageViewController: UIPageViewController {

// MARK: - Public Interface

public extension TabPageViewController {
extension TabPageViewController {

public func displayControllerWithIndex(_ index: Int, direction: UIPageViewControllerNavigationDirection, animated: Bool) {
public func displayControllerWithIndex(_ index: Int, direction: UIPageViewController.NavigationDirection, animated: Bool) {

beforeIndex = index
shouldScrollCurrentBar = false
Expand Down Expand Up @@ -110,7 +110,7 @@ extension TabPageViewController {
fileprivate func setupPageViewController() {
dataSource = self
delegate = self
automaticallyAdjustsScrollViewInsets = false
//automaticallyAdjustsScrollViewInsets = false

setViewControllers([tabItems[beforeIndex].viewController],
direction: .forward,
Expand All @@ -120,7 +120,8 @@ extension TabPageViewController {

fileprivate func setupScrollView() {
// Disable PageViewController's ScrollView bounce
let scrollView = view.subviews.flatMap { $0 as? UIScrollView }.first
let scrollView = view.subviews.compactMap { $0 as? UIScrollView }.first
scrollView?.contentInsetAdjustmentBehavior = .never
scrollView?.scrollsToTop = false
scrollView?.delegate = self
scrollView?.backgroundColor = option.pageBackgoundColor
Expand All @@ -141,52 +142,22 @@ extension TabPageViewController {
fileprivate func configuredTabView() -> TabView {
let tabView = TabView(isInfinity: isInfinity, option: option)
tabView.translatesAutoresizingMaskIntoConstraints = false

let height = NSLayoutConstraint(item: tabView,
attribute: .height,
relatedBy: .equal,
toItem: nil,
attribute: .height,
multiplier: 1.0,
constant: option.tabHeight)
tabView.addConstraint(height)
view.addSubview(tabView)

let top = NSLayoutConstraint(item: tabView,
attribute: .top,
relatedBy: .equal,
toItem: topLayoutGuide,
attribute: .bottom,
multiplier:1.0,
constant: 0.0)

let left = NSLayoutConstraint(item: tabView,
attribute: .leading,
relatedBy: .equal,
toItem: view,
attribute: .leading,
multiplier: 1.0,
constant: 0.0)

let right = NSLayoutConstraint(item: view,
attribute: .trailing,
relatedBy: .equal,
toItem: tabView,
attribute: .trailing,
multiplier: 1.0,
constant: 0.0)

view.addConstraints([top, left, right])

let guide = view.safeAreaLayoutGuide
tabView.heightAnchor.constraint(equalToConstant: option.tabHeight).isActive = true
tabBarTopConstraint = tabView.topAnchor.constraint(equalTo: guide.topAnchor)
tabBarTopConstraint!.isActive = true
tabView.leadingAnchor.constraint(equalTo: guide.leadingAnchor).isActive = true
tabView.trailingAnchor.constraint(equalTo: guide.trailingAnchor).isActive = true

tabView.pageTabItems = tabItems.map({ $0.title})
tabView.updateCurrentIndex(beforeIndex, shouldScroll: true)

tabView.pageItemPressedBlock = { [weak self] (index: Int, direction: UIPageViewControllerNavigationDirection) in
tabView.pageItemPressedBlock = { [weak self] (index: Int, direction: UIPageViewController.NavigationDirection) in
self?.displayControllerWithIndex(index, direction: direction, animated: true)
}

tabBarTopConstraint = top

return tabView
}

Expand All @@ -195,42 +166,13 @@ extension TabPageViewController {
statusView.backgroundColor = option.tabBackgroundColor
statusView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(statusView)

let top = NSLayoutConstraint(item: statusView,
attribute: .top,
relatedBy: .equal,
toItem: view,
attribute: .top,
multiplier:1.0,
constant: 0.0)

let left = NSLayoutConstraint(item: statusView,
attribute: .leading,
relatedBy: .equal,
toItem: view,
attribute: .leading,
multiplier: 1.0,
constant: 0.0)

let right = NSLayoutConstraint(item: view,
attribute: .trailing,
relatedBy: .equal,
toItem: statusView,
attribute: .trailing,
multiplier: 1.0,
constant: 0.0)

let height = NSLayoutConstraint(item: statusView,
attribute: .height,
relatedBy: .equal,
toItem: nil,
attribute: .height,
multiplier: 1.0,
constant: topLayoutGuide.length)

view.addConstraints([top, left, right, height])

statusViewHeightConstraint = height

let guide = view.safeAreaLayoutGuide
statusView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
statusView.leadingAnchor.constraint(equalTo: guide.leadingAnchor).isActive = true
statusView.trailingAnchor.constraint(equalTo: guide.trailingAnchor).isActive = true
statusViewHeightConstraint = statusView.heightAnchor.constraint(equalToConstant: view.safeAreaInsets.top)
statusViewHeightConstraint!.isActive = true
self.statusView = statusView
}

Expand Down Expand Up @@ -260,7 +202,7 @@ extension TabPageViewController {
setupStatusView()
}

statusViewHeightConstraint!.constant = topLayoutGuide.length
statusViewHeightConstraint!.constant = view.safeAreaInsets.top
}

public func showNavigationBar() {
Expand All @@ -270,7 +212,7 @@ extension TabPageViewController {

if option.hidesTopViewOnSwipeType != .none {
tabBarTopConstraint.constant = 0.0
UIView.animate(withDuration: TimeInterval(UINavigationControllerHideShowBarDuration)) {
UIView.animate(withDuration: TimeInterval(UINavigationController.hideShowBarDuration)) {
self.view.layoutIfNeeded()
}
}
Expand All @@ -281,9 +223,8 @@ extension TabPageViewController {

private func updateTabBarOrigin(hidden: Bool) {
guard let tabBarTopConstraint = tabBarTopConstraint else { return }

tabBarTopConstraint.constant = hidden ? -(20.0 + option.tabHeight) : 0.0
UIView.animate(withDuration: TimeInterval(UINavigationControllerHideShowBarDuration)) {
tabBarTopConstraint.constant = hidden ? -(UIApplication.shared.statusBarFrame.height + option.tabHeight) : 0.0
UIView.animate(withDuration: TimeInterval(UINavigationController.hideShowBarDuration)) {
self.view.layoutIfNeeded()
}
}
Expand All @@ -296,7 +237,7 @@ extension TabPageViewController: UIPageViewControllerDataSource {

fileprivate func nextViewController(_ viewController: UIViewController, isAfter: Bool) -> UIViewController? {

guard var index = tabItems.map({$0.viewController}).index(of: viewController) else {
guard var index = tabItems.map({$0.viewController}).firstIndex(of: viewController) else {
return nil
}

Expand Down
Loading