diff --git a/CaseContainer.xcodeproj/project.pbxproj b/CaseContainer.xcodeproj/project.pbxproj index efdc9b2..90dbbf6 100644 --- a/CaseContainer.xcodeproj/project.pbxproj +++ b/CaseContainer.xcodeproj/project.pbxproj @@ -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 */; }; @@ -87,6 +88,7 @@ 04321DA6215F3B5100565864 /* OrdinaryViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrdinaryViewController.swift; sourceTree = ""; }; 0467BD2B2161F2310002C775 /* StartViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartViewController.swift; sourceTree = ""; }; 0467BD4F216280B00002C775 /* Then.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Then.swift; sourceTree = ""; }; + 0467BDD8216485A60002C775 /* FrameTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FrameTests.swift; sourceTree = ""; }; 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 = ""; }; 04DBEE04215A279C009750F2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -155,6 +157,7 @@ 040EFA1E215BCA670082E029 /* TestingFrame.swift */, 040EFA27215BCAA60082E029 /* TestingFrameWithTabBar.swift */, 040EFA29215BCAB10082E029 /* LifeCycleTests.swift */, + 0467BDD8216485A60002C775 /* FrameTests.swift */, 040EFA20215BCA670082E029 /* Info.plist */, ); path = Tests; @@ -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 */, ); diff --git a/Example/AppDelegate.swift b/Example/AppDelegate.swift index 25b9fca..5a262c0 100644 --- a/Example/AppDelegate.swift +++ b/Example/AppDelegate.swift @@ -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 } diff --git a/Example/DemoViewController.swift b/Example/DemoViewController.swift index 9785e37..f2a3c2a 100644 --- a/Example/DemoViewController.swift +++ b/Example/DemoViewController.swift @@ -41,13 +41,13 @@ 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() { @@ -55,23 +55,23 @@ class DemoViewController: CaseContainerViewController { // 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" diff --git a/Sources/CaseContainerView.swift b/Sources/CaseContainerView.swift index 03efeb7..f7f3711 100644 --- a/Sources/CaseContainerView.swift +++ b/Sources/CaseContainerView.swift @@ -10,7 +10,7 @@ import UIKit open class CaseContainerView: CaseContainerBaseView { 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 @@ -27,18 +27,14 @@ open class CaseContainerView: CaseContainerBaseView 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 @@ -53,7 +49,7 @@ open class CaseContainerView: CaseContainerBaseView width: ui.contentsScrollViewContentSize.width, height: ui.contentsScrollViewContentSize.height) $0.frame = rect - $0.backgroundColor = .white + $0.backgroundColor = .blue } public var tabBarHeight: CGFloat { @@ -72,21 +68,18 @@ open class CaseContainerView: CaseContainerBaseView } 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( @@ -95,18 +88,17 @@ open class CaseContainerView: CaseContainerBaseView 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) @@ -128,7 +120,7 @@ open class CaseContainerView: CaseContainerBaseView addSubviews([containerScrollView]) containerScrollView.addSubview(verticalCanvasView) contentsScrollView.addSubview(horizonCanvasView) - verticalCanvasView.addSubviews([headerView, tabScrollView, contentsScrollView]) + verticalCanvasView.addSubviews([tabScrollView, contentsScrollView]) containerScrollView .topAnchor(to: layoutMarginsGuide.topAnchor) @@ -142,18 +134,12 @@ open class CaseContainerView: CaseContainerBaseView .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) @@ -202,15 +188,9 @@ open class CaseContainerView: CaseContainerBaseView 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) } diff --git a/Sources/CaseContainerViewController.swift b/Sources/CaseContainerViewController.swift index ca0d071..a60ad60 100644 --- a/Sources/CaseContainerViewController.swift +++ b/Sources/CaseContainerViewController.swift @@ -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 } @@ -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) @@ -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) { diff --git a/Sources/ParallaxDelegate/ParallaxTableViewController.swift b/Sources/ParallaxDelegate/ParallaxTableViewController.swift index ae844a5..210f10c 100644 --- a/Sources/ParallaxDelegate/ParallaxTableViewController.swift +++ b/Sources/ParallaxDelegate/ParallaxTableViewController.swift @@ -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) +// } } diff --git a/Sources/ParallaxDelegate/ParallaxTableViewDelegate.swift b/Sources/ParallaxDelegate/ParallaxTableViewDelegate.swift index 8c4fa43..8865b4e 100644 --- a/Sources/ParallaxDelegate/ParallaxTableViewDelegate.swift +++ b/Sources/ParallaxDelegate/ParallaxTableViewDelegate.swift @@ -7,53 +7,53 @@ // import UIKit - -public protocol ParallaxTableViewDelegate: class { - func scrollViewDidScroll(scrollView: UIScrollView, tableView: UITableView) -} - -extension CaseContainerViewController: ParallaxTableViewDelegate { - /// scrolling top and bottom is synchronized - public func scrollViewDidScroll(scrollView: UIScrollView, tableView: UITableView) { - let scrollingUp: Bool = scrollView.panGestureRecognizer.translation(in: scrollView).y < 0 - let direction: Direction = scrollingUp ? .up : .down - var childScrollingDownDueToParent = false - let maxiumParallaxY = headerView.frame.height - - switch direction { - case .left: fallthrough - case .right: fallthrough - case .up: - if scrollView == tableView { - if v.containerScrollView.contentOffset.y < maxiumParallaxY && !childScrollingDownDueToParent { - let offsetY = max(min(v.containerScrollView.contentOffset.y + tableView.contentOffset.y, maxiumParallaxY), 0) - v.containerScrollView.contentOffset.y = offsetY - tableView.contentOffset.y = 0 - v.headerView.frame.origin.y = offsetY * 0.5 - } - } - - case .down: - if scrollView == tableView { - if tableView.contentOffset.y < 0 && v.containerScrollView.contentOffset.y > 0 { - let offsetY = max(v.containerScrollView.contentOffset.y - abs(tableView.contentOffset.y), 0) - v.containerScrollView.contentOffset.y = offsetY - v.headerView.frame.origin.y = offsetY * 0.5 - } - } - - if scrollView == v.containerScrollView { - if tableView.contentOffset.y > 0 && v.containerScrollView.contentOffset.y < maxiumParallaxY { - childScrollingDownDueToParent = true - let offsetY = max(tableView.contentOffset.y - (maxiumParallaxY - v.containerScrollView.contentOffset.y), 0) - tableView.contentOffset.y = offsetY - v.contentsScrollView.contentOffset.y = maxiumParallaxY - childScrollingDownDueToParent = false - v.headerView.frame.origin.y = offsetY * 0.5 - } - } - } - } -} - - +// +//public protocol ParallaxTableViewDelegate: class { +// func scrollViewDidScroll(scrollView: UIScrollView, tableView: UITableView) +//} +// +//extension CaseContainerViewController: ParallaxTableViewDelegate { +// /// scrolling top and bottom is synchronized +// public func scrollViewDidScroll(scrollView: UIScrollView, tableView: UITableView) { +// let scrollingUp: Bool = scrollView.panGestureRecognizer.translation(in: scrollView).y < 0 +// let direction: Direction = scrollingUp ? .up : .down +// var childScrollingDownDueToParent = false +// let maxiumParallaxY = headerView.frame.height +// +// switch direction { +// case .left: fallthrough +// case .right: fallthrough +// case .up: +// if scrollView == tableView { +// if v.containerScrollView.contentOffset.y < maxiumParallaxY && !childScrollingDownDueToParent { +// let offsetY = max(min(v.containerScrollView.contentOffset.y + tableView.contentOffset.y, maxiumParallaxY), 0) +// v.containerScrollView.contentOffset.y = offsetY +// tableView.contentOffset.y = 0 +// v.headerView.frame.origin.y = offsetY * 0.5 +// } +// } +// +// case .down: +// if scrollView == tableView { +// if tableView.contentOffset.y < 0 && v.containerScrollView.contentOffset.y > 0 { +// let offsetY = max(v.containerScrollView.contentOffset.y - abs(tableView.contentOffset.y), 0) +// v.containerScrollView.contentOffset.y = offsetY +// v.headerView.frame.origin.y = offsetY * 0.5 +// } +// } +// +// if scrollView == v.containerScrollView { +// if tableView.contentOffset.y > 0 && v.containerScrollView.contentOffset.y < maxiumParallaxY { +// childScrollingDownDueToParent = true +// let offsetY = max(tableView.contentOffset.y - (maxiumParallaxY - v.containerScrollView.contentOffset.y), 0) +// tableView.contentOffset.y = offsetY +// v.contentsScrollView.contentOffset.y = maxiumParallaxY +// childScrollingDownDueToParent = false +// v.headerView.frame.origin.y = offsetY * 0.5 +// } +// } +// } +// } +//} +// +// diff --git a/Sources/TabScrollView/TabScrollView.swift b/Sources/TabScrollView/TabScrollView.swift index 212fe6d..77df72d 100644 --- a/Sources/TabScrollView/TabScrollView.swift +++ b/Sources/TabScrollView/TabScrollView.swift @@ -107,6 +107,8 @@ open class TabScrollView: UIScrollView { btn.highLightedColor = tabBarColor.highLight btn.status = i == 0 ? .on : .off btn.addTarget(vc, action: #selector(vc.tabButtonAction(_:)), for: .touchUpInside) + btn.layer.borderColor = UIColor.black.cgColor + btn.layer.borderWidth = 1 _horizontalCanvas.addSubview(btn) buttons.append(btn) } diff --git a/Tests/FrameTests.swift b/Tests/FrameTests.swift new file mode 100644 index 0000000..79fa1cd --- /dev/null +++ b/Tests/FrameTests.swift @@ -0,0 +1,88 @@ +// +// FrameTests.swift +// Tests +// +// Created by minjuniMac on 03/10/2018. +// Copyright © 2018 mjun. All rights reserved. +// + +import XCTest +@testable import Example + +class FrameTests: XCTestCase { + + var sut: DemoViewController! + var statusBarHeight: CGFloat = UIApplication.shared.statusBarFrame.height + override func setUp() { + // Put setup code here. This method is called before the invocation of each test method in the class. + sut = DemoViewController() + UIApplication.shared.keyWindow?.rootViewController = sut + _ = sut.v + sut.v.layoutIfNeeded() + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + sut = nil + super.tearDown() + } + + func test_ContainerScrollViewFrame_Is_ValidWhenInitializing() { + // 1 + let y: CGFloat = statusBarHeight + let width = UIScreen.mainWidth + let height = UIScreen.mainHeight - y + + // 2 + let rect = CGRect(x: 0, y: y, width: width , height: height) + + // 3 + XCTAssertEqual(sut.v.containerScrollView.frame, rect) + XCTAssertEqual(sut.v.containerScrollView.contentSize, rect.size) + } + + func test_TabBarScrollViewFrame_Is_ValidWhenInitializing() { + // 1 + let y = statusBarHeight + let width = UIScreen.mainWidth + let height = sut.appearence.tabScrollHegiht + + // 2 + let rect = CGRect(x: 0, y: y, width: width, height: height) + let convertOrigin = sut.v.tabScrollView.convert(sut.view.bounds.origin, to: sut.v) + let convertRect = CGRect( + origin: convertOrigin, + size: sut.v.tabScrollView.frame.size) + + // 3 + XCTAssertEqual(convertRect, rect) + } + + func test_ContentScrollViewFrame_IsValidWhenInitializing() { + // 1 + let y = statusBarHeight + sut.tabScrollView.frame.height + let width = UIScreen.mainWidth + let height = UIScreen.mainHeight - y + + // 2 + let rect = CGRect(x: 0, y: y, width: width, height: height) + let convertOrigin = sut.v.contentsScrollView.convert(sut.view.bounds.origin, to: sut.v) + let convertRect = CGRect( + origin: convertOrigin, + size: sut.v.contentsScrollView.frame.size) + + // 3 + XCTAssertEqual(convertRect, rect) + + let contentHeight = UIScreen.mainHeight - statusBarHeight + let contentWidth = UIScreen.mainWidth * CGFloat(sut.viewContorllers.count) + let contentSize = CGSize(width: contentWidth, height: contentHeight) + + XCTAssertEqual(sut.v.contentsScrollView.contentSize, contentSize) + + + } + + + +} diff --git a/Tests/TestingFrame.swift b/Tests/TestingFrame.swift index 3c48a16..dc5470a 100644 --- a/Tests/TestingFrame.swift +++ b/Tests/TestingFrame.swift @@ -9,78 +9,78 @@ import XCTest @testable import Example -class TestingFrame: XCTestCase { - - var sut: DemoViewController! - var statusBarHeight: CGFloat = UIApplication.shared.statusBarFrame.height - override func setUp() { - sut = DemoViewController() - UIApplication.shared.keyWindow?.rootViewController = sut - _ = sut.v - sut.v.layoutIfNeeded() - - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - sut = nil - super.tearDown() - } - - - func test_ContainerScrollViewFrame_Is_ValidWhenInitializing() { - // 1 - let y: CGFloat = statusBarHeight - let width = UIScreen.mainWidth - let height = UIScreen.mainHeight - y - - // 2 - let rect = CGRect(x: 0, y: y, width: width , height: height) - - // 3 - XCTAssertEqual(sut.v.containerScrollView.frame, rect) - } - - func test_verticalCanvasFrameIsValidWhenInitializing() { - // 1 - let width = UIScreen.mainWidth - let headerHeight = sut.v.headerView.frame.height - let tabScrollViewHeight = sut.v.tabScrollView.frame.height - let contentScrollViewHeight = sut.v.contentsScrollView.frame.height - let verticalCanvasHeight = headerHeight + tabScrollViewHeight + contentScrollViewHeight - - // 2 - let rect = CGRect(x: 0, y: 0, width: width, height: verticalCanvasHeight) - - // 3 - XCTAssertEqual(sut.v.verticalCanvasView.frame, rect) - XCTAssertEqual(sut.v.containerScrollView.contentSize, sut.v.verticalCanvasView.frame.size) - } - - func test_TabScrollViewFrameIsValidWhenInitializing() { - XCTAssertEqual(sut.appearence.tabScrollHegiht, sut.v.tabScrollView.frame.height) - } - - func test_ContentScrollViewFrameIsValidWhenInitializing() { - // 1 - let contentScrollViewFrameWidth = UIScreen.mainWidth - let tabScrollViewHeight = sut.v.tabScrollView.frame.height - let headerScrollViewHeight = sut.v.headerView.frame.height - let contentScrollViewFrameHeight = UIScreen.mainHeight - (statusBarHeight + tabScrollViewHeight) - let y = statusBarHeight + headerScrollViewHeight + tabScrollViewHeight - - let rect = CGRect( - x: 0, y: y, - width: contentScrollViewFrameWidth, height: contentScrollViewFrameHeight) - - // 2 - let convertRect = sut.contentsScrollView.convert(sut.v.contentsScrollView.bounds, to: sut.v) - XCTAssertEqual(convertRect, rect) - - // 3 - let contentWidth = UIScreen.mainWidth * CGFloat(sut.viewContorllers.count) - let contentHeight = convertRect.size.height - let contentSize = CGSize(width: contentWidth, height: contentHeight) - XCTAssertEqual(sut.v.horizonCanvasView.frame.size, contentSize) - } -} +//class TestingFrame: XCTestCase { +// +// var sut: DemoViewController! +// var statusBarHeight: CGFloat = UIApplication.shared.statusBarFrame.height +// override func setUp() { +// sut = DemoViewController() +// UIApplication.shared.keyWindow?.rootViewController = sut +// _ = sut.v +// sut.v.layoutIfNeeded() +// +// } +// +// override func tearDown() { +// // Put teardown code here. This method is called after the invocation of each test method in the class. +// sut = nil +// super.tearDown() +// } +// +// +// func test_ContainerScrollViewFrame_Is_ValidWhenInitializing() { +// // 1 +// let y: CGFloat = statusBarHeight +// let width = UIScreen.mainWidth +// let height = UIScreen.mainHeight - y +// +// // 2 +// let rect = CGRect(x: 0, y: y, width: width , height: height) +// +// // 3 +// XCTAssertEqual(sut.v.containerScrollView.frame, rect) +// } +// +// func test_verticalCanvasFrameIsValidWhenInitializing() { +// // 1 +// let width = UIScreen.mainWidth +// let headerHeight = sut.v.headerView.frame.height +// let tabScrollViewHeight = sut.v.tabScrollView.frame.height +// let contentScrollViewHeight = sut.v.contentsScrollView.frame.height +// let verticalCanvasHeight = headerHeight + tabScrollViewHeight + contentScrollViewHeight +// +// // 2 +// let rect = CGRect(x: 0, y: 0, width: width, height: verticalCanvasHeight) +// +// // 3 +// XCTAssertEqual(sut.v.verticalCanvasView.frame, rect) +// XCTAssertEqual(sut.v.containerScrollView.contentSize, sut.v.verticalCanvasView.frame.size) +// } +// +// func test_TabScrollViewFrameIsValidWhenInitializing() { +// XCTAssertEqual(sut.appearence.tabScrollHegiht, sut.v.tabScrollView.frame.height) +// } +// +// func test_ContentScrollViewFrameIsValidWhenInitializing() { +// // 1 +// let contentScrollViewFrameWidth = UIScreen.mainWidth +// let tabScrollViewHeight = sut.v.tabScrollView.frame.height +// let headerScrollViewHeight = sut.v.headerView.frame.height +// let contentScrollViewFrameHeight = UIScreen.mainHeight - (statusBarHeight + tabScrollViewHeight) +// let y = statusBarHeight + headerScrollViewHeight + tabScrollViewHeight +// +// let rect = CGRect( +// x: 0, y: y, +// width: contentScrollViewFrameWidth, height: contentScrollViewFrameHeight) +// +// // 2 +// let convertRect = sut.contentsScrollView.convert(sut.v.contentsScrollView.bounds, to: sut.v) +// XCTAssertEqual(convertRect, rect) +// +// // 3 +// let contentWidth = UIScreen.mainWidth * CGFloat(sut.viewContorllers.count) +// let contentHeight = convertRect.size.height +// let contentSize = CGSize(width: contentWidth, height: contentHeight) +// XCTAssertEqual(sut.v.horizonCanvasView.frame.size, contentSize) +// } +//} diff --git a/Tests/TestingFrameWithTabBar.swift b/Tests/TestingFrameWithTabBar.swift index 68d4f05..2c2069e 100644 --- a/Tests/TestingFrameWithTabBar.swift +++ b/Tests/TestingFrameWithTabBar.swift @@ -8,50 +8,50 @@ import XCTest @testable import Example -class TestingFrameWithTabBar: XCTestCase { - - var sut: DemoViewController! - var tabBarHeight: CGFloat! - var statusBarHeight: CGFloat = UIApplication.shared.statusBarFrame.height - override func setUp() { - super.setUp() - let tabBarController = UITabBarController() - tabBarController.viewControllers = [DemoViewController()] - - sut = tabBarController.viewControllers?.first as? DemoViewController - UIApplication.shared.keyWindow?.rootViewController = tabBarController - _ = sut.view - sut.v.layoutIfNeeded() - - tabBarHeight = sut.tabBarController?.tabBar.frame.height - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - sut = nil - super.tearDown() - } - - func test_ContainerScrollViewFrame_Is_ValidWhenTabBarIsVisible() { - // 2 - let y: CGFloat = UIApplication.shared.statusBarFrame.height - let width = UIScreen.mainWidth - let height = UIScreen.mainHeight - (y + tabBarHeight) - let rect = CGRect(x: 0, y: y, width: width , height: height) - - // 3 - XCTAssertEqual(sut.v.containerScrollView.frame, rect) - } - - func test_ContentScrollViewFrameIsValidWhenTabBarIsVisible() { - let tabScrollViewHeight = sut.v.tabScrollView.frame.height - let headerHeight = sut.v.headerView.frame.height - let y = statusBarHeight + headerHeight + tabScrollViewHeight - let contentScrollViewFrameHeight = UIScreen.mainHeight - (statusBarHeight + tabScrollViewHeight + tabBarHeight) - let rect = CGRect(x: 0, y: y, width: UIScreen.mainWidth, height: contentScrollViewFrameHeight) - - let convertContentScrollViewRect = sut.v.contentsScrollView.convert(sut.v.contentsScrollView.bounds, to: sut.v) - - XCTAssertEqual(convertContentScrollViewRect, rect) - } -} +//class TestingFrameWithTabBar: XCTestCase { +// +// var sut: DemoViewController! +// var tabBarHeight: CGFloat! +// var statusBarHeight: CGFloat = UIApplication.shared.statusBarFrame.height +// override func setUp() { +// super.setUp() +// let tabBarController = UITabBarController() +// tabBarController.viewControllers = [DemoViewController()] +// +// sut = tabBarController.viewControllers?.first as? DemoViewController +// UIApplication.shared.keyWindow?.rootViewController = tabBarController +// _ = sut.view +// sut.v.layoutIfNeeded() +// +// tabBarHeight = sut.tabBarController?.tabBar.frame.height +// } +// +// override func tearDown() { +// // Put teardown code here. This method is called after the invocation of each test method in the class. +// sut = nil +// super.tearDown() +// } +// +// func test_ContainerScrollViewFrame_Is_ValidWhenTabBarIsVisible() { +// // 2 +// let y: CGFloat = UIApplication.shared.statusBarFrame.height +// let width = UIScreen.mainWidth +// let height = UIScreen.mainHeight - (y + tabBarHeight) +// let rect = CGRect(x: 0, y: y, width: width , height: height) +// +// // 3 +// XCTAssertEqual(sut.v.containerScrollView.frame, rect) +// } +// +// func test_ContentScrollViewFrameIsValidWhenTabBarIsVisible() { +// let tabScrollViewHeight = sut.v.tabScrollView.frame.height +// let headerHeight = sut.v.headerView.frame.height +// let y = statusBarHeight + headerHeight + tabScrollViewHeight +// let contentScrollViewFrameHeight = UIScreen.mainHeight - (statusBarHeight + tabScrollViewHeight + tabBarHeight) +// let rect = CGRect(x: 0, y: y, width: UIScreen.mainWidth, height: contentScrollViewFrameHeight) +// +// let convertContentScrollViewRect = sut.v.contentsScrollView.convert(sut.v.contentsScrollView.bounds, to: sut.v) +// +// XCTAssertEqual(convertContentScrollViewRect, rect) +// } +//}