Skip to content

Commit bdf7532

Browse files
committed
Merge branch 'supportNavBarTranslucent'
2 parents 8bff1e5 + 0534cba commit bdf7532

File tree

10 files changed

+88
-63
lines changed

10 files changed

+88
-63
lines changed

Example/ContainerControllerSwift/Base.lproj/Main.storyboard

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22155" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="cIu-62-xtU">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="cIu-62-xtU">
33
<device id="retina4_7" orientation="portrait" appearance="light"/>
44
<dependencies>
55
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22131"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22504"/>
77
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
88
<capability name="System colors in document resources" minToolsVersion="11.0"/>
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@@ -62,7 +62,7 @@
6262
</scenes>
6363
<resources>
6464
<systemColor name="secondaryLabelColor">
65-
<color red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
65+
<color red="0.23529411764705882" green="0.23529411764705882" blue="0.2627450980392157" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
6666
</systemColor>
6767
<systemColor name="systemBackgroundColor">
6868
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>

Example/ContainerControllerSwift/ExampleAddCollectionView/ExampleAddCollectionViewController.storyboard

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22155" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina4_7" orientation="portrait" appearance="light"/>
44
<dependencies>
55
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22131"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22504"/>
77
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
88
<capability name="System colors in document resources" minToolsVersion="11.0"/>
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@@ -16,9 +16,32 @@
1616
<view key="view" contentMode="scaleToFill" id="jmi-Lo-St4">
1717
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1818
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19+
<subviews>
20+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="gqJ-oN-JCK">
21+
<rect key="frame" x="110.5" y="50" width="154" height="50"/>
22+
<constraints>
23+
<constraint firstAttribute="height" constant="50" id="MXC-rS-qfY"/>
24+
</constraints>
25+
<fontDescription key="fontDescription" name="HelveticaNeue-Bold" family="Helvetica Neue" pointSize="18"/>
26+
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
27+
<state key="normal" title="isTranslucent true">
28+
<color key="titleColor" systemColor="systemBlueColor"/>
29+
</state>
30+
<connections>
31+
<action selector="btnChangeTranslucentAction:" destination="p3c-kf-PfN" eventType="touchUpInside" id="hjO-rR-Ij1"/>
32+
</connections>
33+
</button>
34+
</subviews>
1935
<viewLayoutGuide key="safeArea" id="QCP-uk-H24"/>
2036
<color key="backgroundColor" systemColor="opaqueSeparatorColor"/>
37+
<constraints>
38+
<constraint firstItem="gqJ-oN-JCK" firstAttribute="top" secondItem="QCP-uk-H24" secondAttribute="top" constant="30" id="2Vg-iw-6Rl"/>
39+
<constraint firstItem="gqJ-oN-JCK" firstAttribute="centerX" secondItem="jmi-Lo-St4" secondAttribute="centerX" id="Crs-BD-puY"/>
40+
</constraints>
2141
</view>
42+
<connections>
43+
<outlet property="btnChangeTranslucent" destination="gqJ-oN-JCK" id="34t-Kh-blv"/>
44+
</connections>
2245
</viewController>
2346
<placeholder placeholderIdentifier="IBFirstResponder" id="Uzt-sR-4xA" sceneMemberID="firstResponder"/>
2447
</objects>
@@ -27,7 +50,10 @@
2750
</scenes>
2851
<resources>
2952
<systemColor name="opaqueSeparatorColor">
30-
<color red="0.77647058820000003" green="0.77647058820000003" blue="0.7843137255" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
53+
<color red="0.77647058823529413" green="0.77647058823529413" blue="0.78431372549019607" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
54+
</systemColor>
55+
<systemColor name="systemBlueColor">
56+
<color red="0.0" green="0.47843137254901963" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
3157
</systemColor>
3258
</resources>
3359
</document>

Example/ContainerControllerSwift/ExampleAddCollectionView/ExampleAddCollectionViewController.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ class ExampleAddCollectionViewController: StoryboardController {
1313

1414
var container: ContainerController!
1515

16+
@IBOutlet var btnChangeTranslucent: UIButton!
1617
// MARK: - Init
1718

1819
override func viewDidLoad() {
1920
super.viewDidLoad()
2021

2122
title = "Example Add CollectionView"
2223

24+
btnUpdateText()
25+
2326
let layoutC = ContainerLayout()
2427
layoutC.positions = ContainerPosition(top: 100, middle: 250, bottom: 70)
2528
container = ContainerController(addTo: self, layout: layoutC)
@@ -34,6 +37,24 @@ class ExampleAddCollectionViewController: StoryboardController {
3437
container.move(type: .middle)
3538
}
3639

40+
@IBAction func btnChangeTranslucentAction(_ sender: UIButton) {
41+
42+
guard let translucent = navigationController?.navigationBar.isTranslucent else { return }
43+
44+
navigationController?.navigationBar.isTranslucent = !translucent
45+
46+
btnUpdateText()
47+
48+
container.move(type: container.moveType)
49+
}
50+
51+
func btnUpdateText() {
52+
53+
guard let translucent = navigationController?.navigationBar.isTranslucent else { return }
54+
55+
btnChangeTranslucent.setTitle("NavBar isTranslucent \(translucent)", for: .normal)
56+
}
57+
3758
func addCollectionView() -> UICollectionView {
3859

3960
let layout = UICollectionViewFlowLayout()

Example/ContainerControllerSwift/ExamplesSettings/Container/ExamplesContainerController.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class ExamplesContainerController: ContainerController, ExampleCellDelegate {
7070
ExampleSwitchCellItem(height: h, delegate: self, type: .shadowBackground, value: false),
7171
ExampleSliderCellItem(height: h, delegate: self, type: .shadowContainer, value: 0.2, maximumValue: 1.0),
7272
ExampleSliderCellItem(height: h, delegate: self, type: .cornerRadius, value: 15, maximumValue: 140),
73+
74+
ExampleSwitchCellItem(height: h, delegate: self, type: .navbarTranslucent, value: false),
75+
7376
ExampleSwitchCellItem(height: h, delegate: self, type: .movingEnabled, value: true),
7477
ExampleSwitchCellItem(height: h, delegate: self, type: .trackingPosition, value: false),
7578
ExampleSliderCellItem(height: h, delegate: self, type: .footerPadding, value: 0, maximumValue: Float(ContainerDevice.screenMax)),
@@ -122,6 +125,8 @@ class ExamplesContainerController: ContainerController, ExampleCellDelegate {
122125

123126
case .shadowContainer: self.view.addShadow(opacity: value)
124127

128+
case .navbarTranslucent: self.controller?.navigationController?.navigationBar.isTranslucent = boolValue; move(type: moveType)
129+
125130
case .movingEnabled: set(movingEnabled: boolValue)
126131

127132
case .trackingPosition: set(trackingPosition: boolValue)

Example/ContainerControllerSwift/ExamplesSettings/UI/Cell/ExampleCellStyle.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extension ExampleCell {
2020
public enum Style: String {
2121
case `default` = ""
2222
case shadowContainer = "ShadowContainer"
23+
case navbarTranslucent = "NavbarTranslucent"
2324
case movingEnabled = "MovingEnabled"
2425
case cornerRadius = "CornerRadius"
2526
case footerPadding = "FooterView.Padding"

Example/ContainerControllerSwift/Maps/MapsViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class MapsViewController: StoryboardController, MapsContainerControllerDelegate,
5959
override func viewWillAppear(_ animated: Bool) {
6060
super.viewWillAppear(animated)
6161

62+
navigationController?.navigationBar.isTranslucent = false
63+
6264
setNeedsStatusBarAppearanceUpdate()
6365

6466
navBar(hide: true)

Example/ContainerControllerSwift/ViewController.swift

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ class ViewController: UIViewController {
1717
override func viewDidLoad() {
1818
super.viewDidLoad()
1919

20-
configureNavigationBar(largeTitleColor: .label, backgoundColor: .systemGroupedBackground, tintColor: .systemBlue, title: "ContainerController", preferredLargeTitle: false)
21-
2220
title = "ContainerController"
2321

2422
navigationController?.interactivePopGestureRecognizer?.delegate = self
2523
navigationController?.interactivePopGestureRecognizer?.isEnabled = true
26-
24+
navigationController?.view.backgroundColor = .systemGroupedBackground
2725
items = [
2826
TitleTextItem(title: "Maps.app", clss: MapsViewController.self),
2927
TitleTextItem(title: "Example. Settings", clss: ExamplesSettingsViewController.self),
@@ -48,34 +46,6 @@ class ViewController: UIViewController {
4846

4947
}
5048

51-
extension ViewController {
52-
func configureNavigationBar(largeTitleColor: UIColor, backgoundColor: UIColor, tintColor: UIColor, title: String, preferredLargeTitle: Bool) {
53-
if #available(iOS 13.0, *) {
54-
let navBarAppearance = UINavigationBarAppearance()
55-
navBarAppearance.configureWithOpaqueBackground()
56-
navBarAppearance.largeTitleTextAttributes = [.foregroundColor: largeTitleColor]
57-
navBarAppearance.titleTextAttributes = [.foregroundColor: largeTitleColor]
58-
navBarAppearance.backgroundColor = backgoundColor
59-
60-
navigationController?.navigationBar.standardAppearance = navBarAppearance
61-
navigationController?.navigationBar.compactAppearance = navBarAppearance
62-
navigationController?.navigationBar.scrollEdgeAppearance = navBarAppearance
63-
64-
navigationController?.navigationBar.prefersLargeTitles = preferredLargeTitle
65-
navigationController?.navigationBar.isTranslucent = false
66-
navigationController?.navigationBar.tintColor = tintColor
67-
navigationItem.title = title
68-
69-
} else {
70-
// Fallback on earlier versions
71-
navigationController?.navigationBar.barTintColor = backgoundColor
72-
navigationController?.navigationBar.tintColor = tintColor
73-
navigationController?.navigationBar.isTranslucent = false
74-
navigationItem.title = title
75-
}
76-
}
77-
}
78-
7949
extension ViewController: UIGestureRecognizerDelegate {
8050

8151
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) -> Bool {

Sources/ContainerController/ContainerController.swift

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ open class ContainerController: NSObject {
218218

219219
shadowHiddenCheck()
220220

221-
delegate?.containerControllerRotation(self)
221+
delegate?.containerControllerRotation?(self)
222222

223223
calculationView()
224224
calculationScrollViewHeight(from: .rotation)
@@ -357,7 +357,7 @@ open class ContainerController: NSObject {
357357
}
358358

359359
@objc private func shadowButtonAction() {
360-
delegate?.containerControllerShadowClick(self)
360+
delegate?.containerControllerShadowClick?(self)
361361
}
362362

363363
// MARK: - Create Container-View
@@ -477,7 +477,11 @@ open class ContainerController: NSObject {
477477
transform.ty = ((positionTop / 2) + (transform.ty / 2))
478478
}
479479

480-
let position = transform.ty
480+
var position = transform.ty
481+
if topTranslucent {
482+
position = position + topBarHeight
483+
}
484+
481485
let type: ContainerMoveType = moveType
482486
let from: ContainerFromType = .pan
483487
let animation = false
@@ -555,7 +559,7 @@ open class ContainerController: NSObject {
555559
scrollInsetsBottom = 0.0
556560
}
557561

558-
let top: CGFloat = layout.scrollInsets.top
562+
var top: CGFloat = layout.scrollInsets.top
559563
let bottom: CGFloat = layout.scrollInsets.bottom + scrollInsetsBottom
560564

561565
let indicatorTop: CGFloat = layout.scrollIndicatorInsets.top
@@ -575,6 +579,10 @@ open class ContainerController: NSObject {
575579
height = 0
576580
}
577581

582+
if topTranslucent {
583+
height = height + topBarHeight
584+
}
585+
578586
if animation ,
579587
!isScrolling,
580588
footerView == nil,
@@ -735,7 +743,10 @@ open class ContainerController: NSObject {
735743
from: ContainerFromType = .custom,
736744
completion: (() -> Void)? = nil) {
737745

738-
let position = positionMoveFrom(type: type)
746+
var position = positionMoveFrom(type: type)
747+
if topTranslucent {
748+
position = position + topBarHeight
749+
}
739750

740751
move(position: position,
741752
animation: animation,
@@ -834,7 +845,7 @@ open class ContainerController: NSObject {
834845
type: ContainerMoveType,
835846
animation: Bool) {
836847

837-
delegate?.containerControllerMove(self, position: position, type: type, animation: animation)
848+
delegate?.containerControllerMove?(self, position: position, type: type, animation: animation)
838849
}
839850

840851
//MARK: - Shadow Alpha Level
@@ -1229,7 +1240,10 @@ extension ContainerController: UIScrollViewDelegate {
12291240

12301241
scrollTransform = view.transform
12311242

1232-
let top: CGFloat = positionTop
1243+
var top: CGFloat = positionTop
1244+
if topTranslucent {
1245+
top = top + topBarHeight
1246+
}
12331247

12341248
if gesture.state == .ended {
12351249
scrollOnceBeginDragging = false

Sources/ContainerController/ContainerControllerDelegate.swift

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,16 @@
99
import UIKit
1010

1111
@available(iOS 13.0, *)
12-
public protocol ContainerControllerDelegate {
12+
@objc public protocol ContainerControllerDelegate {
1313

1414
/// Reports rotation and orientation changes
15-
func containerControllerRotation(_ containerController: ContainerController)
15+
@objc optional func containerControllerRotation(_ containerController: ContainerController)
1616

1717
/// Reports a click on the background shadow
18-
func containerControllerShadowClick(_ containerController: ContainerController)
18+
@objc optional func containerControllerShadowClick(_ containerController: ContainerController)
1919

2020
/// Reports the changes current position of the container, after its use
21-
func containerControllerMove(_ containerController: ContainerController, position: CGFloat, type: ContainerMoveType, animation: Bool)
21+
@objc optional func containerControllerMove(_ containerController: ContainerController, position: CGFloat, type: ContainerMoveType, animation: Bool)
2222

2323
}
2424

25-
@available(iOS 13.0, *)
26-
public extension ContainerControllerDelegate {
27-
28-
func containerControllerRotation(_ containerController: ContainerController) {
29-
}
30-
31-
32-
func containerControllerShadowClick(_ containerController: ContainerController) {
33-
}
34-
35-
func containerControllerMove(_ containerController: ContainerController, position: CGFloat, type: ContainerMoveType, animation: Bool) {
36-
}
37-
}
38-

Sources/ContainerController/ContainerTypes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import UIKit
1010

1111
typealias ContainerCompletion = () -> Void
1212

13-
public enum ContainerMoveType {
13+
@objc public enum ContainerMoveType: Int {
1414
case top
1515
case middle
1616
case bottom

0 commit comments

Comments
 (0)