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
4 changes: 4 additions & 0 deletions CaseContainer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
04321DA7215F3B5100565864 /* OrdinaryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04321DA6215F3B5100565864 /* OrdinaryViewController.swift */; };
0467BD2C2161F2310002C775 /* StartViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0467BD2B2161F2310002C775 /* StartViewController.swift */; };
0467BD6F2162826E0002C775 /* Then.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0467BD4F216280B00002C775 /* Then.swift */; };
0467BDD9216485A60002C775 /* FrameTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0467BDD8216485A60002C775 /* FrameTests.swift */; };
04DBEE11215A279C009750F2 /* CaseContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 04DBEE03215A279C009750F2 /* CaseContainer.h */; settings = {ATTRIBUTES = (Public, ); }; };
04DBEE1F215A2A2B009750F2 /* CaseContainerBaseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04DBEE1E215A2A2B009750F2 /* CaseContainerBaseView.swift */; };
04DBEE21215A2A33009750F2 /* CaseContainerBaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04DBEE20215A2A33009750F2 /* CaseContainerBaseViewController.swift */; };
Expand Down Expand Up @@ -87,6 +88,7 @@
04321DA6215F3B5100565864 /* OrdinaryViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrdinaryViewController.swift; sourceTree = "<group>"; };
0467BD2B2161F2310002C775 /* StartViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartViewController.swift; sourceTree = "<group>"; };
0467BD4F216280B00002C775 /* Then.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Then.swift; sourceTree = "<group>"; };
0467BDD8216485A60002C775 /* FrameTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FrameTests.swift; sourceTree = "<group>"; };
04DBEE00215A279C009750F2 /* CaseContainer.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CaseContainer.framework; sourceTree = BUILT_PRODUCTS_DIR; };
04DBEE03215A279C009750F2 /* CaseContainer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CaseContainer.h; sourceTree = "<group>"; };
04DBEE04215A279C009750F2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -155,6 +157,7 @@
040EFA1E215BCA670082E029 /* TestingFrame.swift */,
040EFA27215BCAA60082E029 /* TestingFrameWithTabBar.swift */,
040EFA29215BCAB10082E029 /* LifeCycleTests.swift */,
0467BDD8216485A60002C775 /* FrameTests.swift */,
040EFA20215BCA670082E029 /* Info.plist */,
);
path = Tests;
Expand Down Expand Up @@ -402,6 +405,7 @@
buildActionMask = 2147483647;
files = (
040EFA28215BCAA60082E029 /* TestingFrameWithTabBar.swift in Sources */,
0467BDD9216485A60002C775 /* FrameTests.swift in Sources */,
040EFA1F215BCA670082E029 /* TestingFrame.swift in Sources */,
040EFA2A215BCAB10082E029 /* LifeCycleTests.swift in Sources */,
);
Expand Down
3 changes: 2 additions & 1 deletion Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = StartViewController()
// window?.rootViewController = StartViewController()
window?.rootViewController = DemoViewController()
window?.makeKeyAndVisible()
return true
}
Expand Down
24 changes: 12 additions & 12 deletions Example/DemoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,37 +41,37 @@ class DemoViewController: CaseContainerViewController {

view.addSubview(dismissButton)
dismissButton.bringSubviewToFront(containerScrollView)

imageView = UIImageView(image: UIImage(named: "swiss.jpg"))
if let imageView = imageView {
headerView.addSubview(imageView)
imageView.frame = CGRect(x: 0, y: 0,
width: UIScreen.mainWidth, height: appearence.headerHeight)
}
//
// imageView = UIImageView(image: UIImage(named: "swiss.jpg"))
// if let imageView = imageView {
// headerView.addSubview(imageView)
// imageView.frame = CGRect(x: 0, y: 0,
// width: UIScreen.mainWidth, height: appearence.headerHeight)
// }
}

required init() {
super.init()
// 1
let childViewController1 = ChildTableViewController()
childViewController1.title = "First Tab"
childViewController1.delegate = self
// childViewController1.delegate = self

let childViewController2 = ChildTableViewController()
childViewController2.title = "Second Tab"
childViewController2.delegate = self
// childViewController2.delegate = self

let childViewController3 = ChildTableViewController()
childViewController3.title = "Third Tab"
childViewController3.delegate = self
// childViewController3.delegate = self

let childViewController4 = ChildTableViewController()
childViewController4.title = "Fourth Tab"
childViewController4.delegate = self
// childViewController4.delegate = self

let childViewController5 = ChildTableViewController()
childViewController5.title = "Fifth Tab"
childViewController5.delegate = self
// childViewController5.delegate = self

let childViewController6 = OrdinaryViewController()
childViewController6.title = "Sixth Tab"
Expand Down
46 changes: 13 additions & 33 deletions Sources/CaseContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

open class CaseContainerView: CaseContainerBaseView<CaseContainerViewController> {
public private(set) var containerScrollView = UIScrollView().then {
$0.backgroundColor = .white
$0.backgroundColor = .red
$0.showsHorizontalScrollIndicator = false
$0.showsVerticalScrollIndicator = false
/// was specified unidirection Scrolling, this direction of scrollView is vertical
Expand All @@ -27,18 +27,14 @@ open class CaseContainerView: CaseContainerBaseView<CaseContainerViewController>
This property is containerScrollView's contentView
*/
lazy public private(set) var verticalCanvasView = UIView().then {
$0.backgroundColor = .white
}

public var headerView: UIView = UIView().then {
$0.backgroundColor = .white
$0.backgroundColor = .brown
}

public var tabScrollView = TabScrollView()

public var contentsScrollView = UIScrollView().then {
$0.bounces = false
$0.backgroundColor = .white
$0.bounces = true
$0.backgroundColor = .purple
$0.isDirectionalLockEnabled = true
$0.showsVerticalScrollIndicator = false
$0.isPagingEnabled = true
Expand All @@ -53,7 +49,7 @@ open class CaseContainerView: CaseContainerBaseView<CaseContainerViewController>
width: ui.contentsScrollViewContentSize.width,
height: ui.contentsScrollViewContentSize.height)
$0.frame = rect
$0.backgroundColor = .white
$0.backgroundColor = .blue
}

public var tabBarHeight: CGFloat {
Expand All @@ -72,21 +68,18 @@ open class CaseContainerView: CaseContainerBaseView<CaseContainerViewController>
}

struct UI {
var headerViewHeight: CGFloat
var tabScrollViewHeight: CGFloat
var contentsScrollViewFrameSize: CGSize
var contentsScrollViewContentSize: CGSize
var containerScrollViewContentSize: CGSize

init(containerViewController: CaseContainerViewController,
headerHeight: CGFloat,
tabScrollHeaight: CGFloat,
tabBarHeight: CGFloat) {
guard containerViewController.viewContorllers.count > 0 else {
fatalError("you must Implement ChildViewController")
}
let numberOfChildVierControlelr: CGFloat = CGFloat(containerViewController.viewContorllers.count)
headerViewHeight = headerHeight
tabScrollViewHeight = tabScrollHeaight

contentsScrollViewFrameSize = CGSize(
Expand All @@ -95,18 +88,17 @@ open class CaseContainerView: CaseContainerBaseView<CaseContainerViewController>

contentsScrollViewContentSize = CGSize(
width: UIScreen.mainWidth * numberOfChildVierControlelr,
height: contentsScrollViewFrameSize.height)
height: UIScreen.mainHeight - UIApplication.statusBarHeight )

containerScrollViewContentSize = CGSize(
width: UIScreen.mainWidth,
height: headerViewHeight + tabScrollViewHeight + contentsScrollViewFrameSize.height)
height: tabScrollViewHeight + contentsScrollViewFrameSize.height)

}
}

lazy var ui = UI(
containerViewController: vc,
headerHeight: vc.appearence.headerHeight,
tabScrollHeaight: vc.appearence.tabScrollHegiht,
tabBarHeight: tabBarHeight)

Expand All @@ -128,7 +120,7 @@ open class CaseContainerView: CaseContainerBaseView<CaseContainerViewController>
addSubviews([containerScrollView])
containerScrollView.addSubview(verticalCanvasView)
contentsScrollView.addSubview(horizonCanvasView)
verticalCanvasView.addSubviews([headerView, tabScrollView, contentsScrollView])
verticalCanvasView.addSubviews([tabScrollView, contentsScrollView])

containerScrollView
.topAnchor(to: layoutMarginsGuide.topAnchor)
Expand All @@ -142,18 +134,12 @@ open class CaseContainerView: CaseContainerBaseView<CaseContainerViewController>
.bottomAnchor(to: containerScrollView.bottomAnchor)
.leadingAnchor(to: containerScrollView.leadingAnchor)
.trailingAnchor(to: containerScrollView.trailingAnchor)

.dimensionAnchors(size: ui.containerScrollViewContentSize)
.activateAnchors()

headerView
.topAnchor(to: verticalCanvasView.topAnchor)
.leadingAnchor(to: verticalCanvasView.leadingAnchor)
.trailingAnchor(to: verticalCanvasView.trailingAnchor)
.heightAnchor(constant: ui.headerViewHeight)
.activateAnchors()

tabScrollView
.topAnchor(to: headerView.bottomAnchor)
.topAnchor(to: verticalCanvasView.topAnchor)
.leadingAnchor(to: verticalCanvasView.leadingAnchor)
.trailingAnchor(to: verticalCanvasView.trailingAnchor)
.heightAnchor(constant: ui.tabScrollViewHeight)
Expand Down Expand Up @@ -202,15 +188,9 @@ open class CaseContainerView: CaseContainerBaseView<CaseContainerViewController>
horizonCanvasView.addSubview(initialChildVC.view)

// 3. determine child View Controller`s view frame
if initialChildVC is ParallaxTableViewController {
initialChildVC.view.frame = CGRect(x: 0, y: 0, width: ui.contentsScrollViewFrameSize.width, height: ui.contentsScrollViewContentSize.height)
}else {
// if it is not ParallaxTableViewController
let vaildViewHeight = UIScreen.mainHeight - UIApplication.statusBarHeight
let scaleRatio = ui.contentsScrollViewContentSize.height / vaildViewHeight
initialChildVC.view.transform = CGAffineTransform(scaleX: 1.0, y: scaleRatio)
initialChildVC.view.frame.origin = CGPoint.zero
}
initialChildVC.view.frame = CGRect(x: 0, y: 0,
width: ui.contentsScrollViewFrameSize.width,
height: ui.contentsScrollViewContentSize.height)

initialChildVC.didMove(toParent: vc)
}
Expand Down
51 changes: 22 additions & 29 deletions Sources/CaseContainerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ open class CaseContainerViewController: CaseContainerBaseViewController {
lazy open private(set) var v = CaseContainerView(controllBy: self)
weak open var delegate: CaseContainerDelegate?

open weak var headerView: UIView! { return v.headerView }

open weak var tabScrollView: TabScrollView! { return v.tabScrollView }
open weak var contentsScrollView: UIScrollView! { return v.contentsScrollView }
open weak var containerScrollView: UIScrollView! { return v.containerScrollView }
Expand Down Expand Up @@ -90,19 +90,11 @@ open class CaseContainerViewController: CaseContainerBaseViewController {
if let childVC = viewContorllers.at(index) {
addChild(childVC)
v.horizonCanvasView.addSubview(childVC.view)

if childVC is ParallaxTableViewController {
let indexWidth: CGFloat = v.ui.contentsScrollViewFrameSize.width
let rect = CGRect(
x: indexWidth * CGFloat(index), y: 0,
width: indexWidth, height: v.ui.contentsScrollViewContentSize.height)
childVC.view.frame = rect
}else {
let vaildViewHeight = UIScreen.mainHeight - UIApplication.statusBarHeight
let scaleRatio = v.ui.contentsScrollViewContentSize.height / vaildViewHeight
childVC.view.transform = CGAffineTransform(scaleX: 1.0, y: scaleRatio)
childVC.view.frame.origin = CGPoint(x: v.ui.contentsScrollViewFrameSize.width * CGFloat(index), y: 0)
}
let indexWidth: CGFloat = v.ui.contentsScrollViewFrameSize.width
let rect = CGRect(
x: indexWidth * CGFloat(index), y: 0,
width: indexWidth, height: v.ui.contentsScrollViewContentSize.height)
childVC.view.frame = rect

childVC.didMove(toParent: self)
childVC.beginAppearanceTransition(true, animated: true)
Expand Down Expand Up @@ -252,22 +244,23 @@ extension CaseContainerViewController: UIScrollViewDelegate {
scrollViewStatus.startDraggingOffsetX = ceil(scrollView.contentOffset.x)
}
}
}else if scrollView === containerScrollView {
let maxiumOffsetY = v.headerView.frame.height
let progress = containerScrollView.contentOffset.y / maxiumOffsetY

// temporarily...
// To synchronize the contentOffset of the child view controller, contentOffset of the container ScrollView
if progress == 0 {
viewContorllers.forEach {
if $0 is ParallaxTableViewController {
($0 as? ParallaxTableViewController)?.tableView.contentOffset = CGPoint.zero
}
}
}
delegate?.caseContainer(parallaxHeader: progress)

}
// else if scrollView === containerScrollView {
// let maxiumOffsetY = v.headerView.frame.height
// let progress = containerScrollView.contentOffset.y / maxiumOffsetY
//
// // temporarily...
// // To synchronize the contentOffset of the child view controller, contentOffset of the container ScrollView
// if progress == 0 {
// viewContorllers.forEach {
// if $0 is ParallaxTableViewController {
// ($0 as? ParallaxTableViewController)?.tableView.contentOffset = CGPoint.zero
// }
// }
// }
// delegate?.caseContainer(parallaxHeader: progress)
//
// }
}

open func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
Expand Down
10 changes: 5 additions & 5 deletions Sources/ParallaxDelegate/ParallaxTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import UIKit

open class ParallaxTableViewController: UITableViewController {
weak open var delegate: ParallaxTableViewDelegate?

open override func scrollViewDidScroll(_ scrollView: UIScrollView) {
delegate?.scrollViewDidScroll(scrollView: scrollView, tableView: tableView)
}
// weak open var delegate: ParallaxTableViewDelegate?
//
// open override func scrollViewDidScroll(_ scrollView: UIScrollView) {
// delegate?.scrollViewDidScroll(scrollView: scrollView, tableView: tableView)
// }
}
Loading