Skip to content

Commit

Permalink
Merge pull request #537 from rechsteiner/3.0
Browse files Browse the repository at this point in the history
Version 3.0
  • Loading branch information
rechsteiner authored Dec 3, 2020
2 parents f714811 + 5edccdd commit b67447a
Show file tree
Hide file tree
Showing 34 changed files with 3,997 additions and 912 deletions.
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import UIKit
import Parchment

/// Parchment provides a custom `UIPageViewController` alternative
/// if you need better delegate methods called `PageViewController`.
class PageViewExampleViewController: UIViewController {
let viewControllers: [UIViewController] = [
ContentViewController(index: 0),
ContentViewController(index: 1),
ContentViewController(index: 2),
ContentViewController(index: 3),
ContentViewController(index: 4),
]

override func viewDidLoad() {
let pageViewController = PageViewController()
pageViewController.dataSource = self
pageViewController.delegate = self
pageViewController.selectViewController(viewControllers[0], direction: .none)

addChild(pageViewController)
view.addSubview(pageViewController.view)
view.constrainToEdges(pageViewController.view)
pageViewController.didMove(toParent: self)
}
}

extension PageViewExampleViewController: PageViewControllerDataSource {
func pageViewController(
_ pageViewController: PageViewController,
viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
guard let index = viewControllers.firstIndex(of: viewController) else { return nil }
if index > 0 {
return viewControllers[index - 1]
}
return nil
}

func pageViewController(
_ pageViewController: PageViewController,
viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
guard let index = viewControllers.firstIndex(of: viewController) else { return nil }
if index < viewControllers.count - 1 {
return viewControllers[index + 1]
}
return nil
}
}

extension PageViewExampleViewController: PageViewControllerDelegate {
func pageViewController(_ pageViewController: PageViewController, willStartScrollingFrom startingViewController: UIViewController, destinationViewController: UIViewController) {
print("willStartScrollingFrom: ",
startingViewController.title ?? "",
destinationViewController.title ?? "")
}

func pageViewController(_ pageViewController: PageViewController, isScrollingFrom startingViewController: UIViewController, destinationViewController: UIViewController?, progress: CGFloat) {
print("isScrollingFrom: ",
startingViewController.title ?? "",
destinationViewController?.title ?? "",
progress)
}

func pageViewController(_ pageViewController: PageViewController, didFinishScrollingFrom startingViewController: UIViewController, destinationViewController: UIViewController, transitionSuccessful: Bool) {
print("didFinishScrollingFrom: ",
startingViewController.title ?? "",
destinationViewController.title ?? "",
transitionSuccessful)
}
}
5 changes: 5 additions & 0 deletions Example/ExamplesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum Example: CaseIterable {
case scroll
case header
case multipleCells
case pageViewController

var title: String {
switch self {
Expand Down Expand Up @@ -40,6 +41,8 @@ enum Example: CaseIterable {
return "Header above menu"
case .multipleCells:
return "Multiple cells"
case .pageViewController:
return "PageViewController"
}
}
}
Expand Down Expand Up @@ -118,6 +121,8 @@ final class ExamplesViewController: UITableViewController {
return HeaderViewController(nibName: nil, bundle: nil)
case .multipleCells:
return MultipleCellsViewController(nibName: nil, bundle: nil)
case .pageViewController:
return PageViewExampleViewController(nibName: nil, bundle: nil)
}
}

Expand Down
26 changes: 18 additions & 8 deletions Example/Resources/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15400" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="q4m-KO-mBR">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17156" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="q4m-KO-mBR">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15404"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17125"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -34,9 +35,9 @@
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="qJk-Tf-P33">
<rect key="frame" x="0.0" y="0.0" width="414" height="808"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="44O-Qs-6IP">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="CellIdentifier" id="44O-Qs-6IP">
<rect key="frame" x="0.0" y="28" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="44O-Qs-6IP" id="BGG-Ma-XNX">
Expand All @@ -45,6 +46,7 @@
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<sections/>
<connections>
<outlet property="dataSource" destination="zQo-ny-4EL" id="7xZ-91-GMB"/>
<outlet property="delegate" destination="zQo-ny-4EL" id="GmV-SB-b2E"/>
Expand All @@ -71,11 +73,11 @@
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Second" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="T6v-38-Gay">
<rect key="frame" x="151" y="427.5" width="112" height="41"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle0"/>
<color key="textColor" systemColor="systemGrayColor" red="0.5568627451" green="0.5568627451" blue="0.57647058819999997" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="textColor" systemColor="systemGrayColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="T6v-38-Gay" firstAttribute="centerX" secondItem="haj-WE-mYV" secondAttribute="centerX" id="4ce-k9-1ec"/>
<constraint firstItem="T6v-38-Gay" firstAttribute="centerY" secondItem="haj-WE-mYV" secondAttribute="centerY" id="4p1-s6-AXx"/>
Expand All @@ -101,11 +103,11 @@
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="First" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="u8Q-Z0-CJC">
<rect key="frame" x="175.5" y="427.5" width="63.5" height="41"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle0"/>
<color key="textColor" systemColor="systemGrayColor" red="0.5568627451" green="0.5568627451" blue="0.57647058819999997" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="textColor" systemColor="systemGrayColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="u8Q-Z0-CJC" firstAttribute="centerY" secondItem="7ib-Vw-aOY" secondAttribute="centerY" id="UIE-88-zeq"/>
<constraint firstItem="u8Q-Z0-CJC" firstAttribute="centerX" secondItem="7ib-Vw-aOY" secondAttribute="centerX" id="nby-zc-JeO"/>
Expand All @@ -117,4 +119,12 @@
<point key="canvasLocation" x="-484" y="1135"/>
</scene>
</scenes>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
<systemColor name="systemGrayColor">
<color red="0.55686274509803924" green="0.55686274509803924" blue="0.57647058823529407" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
</resources>
</document>
Loading

0 comments on commit b67447a

Please sign in to comment.