Skip to content

Commit 831b2f1

Browse files
committed
Added support for the change isTranslucent NavigationBar
1 parent 8bff1e5 commit 831b2f1

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

Example/ContainerControllerSwift/ExampleAddCollectionView/ExampleAddCollectionViewController.storyboard

Lines changed: 26 additions & 2 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,8 +16,29 @@
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="87.5" y="50" width="200" height="50"/>
22+
<constraints>
23+
<constraint firstAttribute="width" constant="200" id="3QE-nw-Od3"/>
24+
<constraint firstAttribute="height" constant="50" id="MXC-rS-qfY"/>
25+
</constraints>
26+
<fontDescription key="fontDescription" name="HelveticaNeue-Bold" family="Helvetica Neue" pointSize="20"/>
27+
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
28+
<state key="normal" title="isTranslucent True">
29+
<color key="titleColor" systemColor="systemBlueColor"/>
30+
</state>
31+
<connections>
32+
<action selector="buttonChangeTranslucent:" destination="p3c-kf-PfN" eventType="touchUpInside" id="FG2-xH-GUG"/>
33+
</connections>
34+
</button>
35+
</subviews>
1936
<viewLayoutGuide key="safeArea" id="QCP-uk-H24"/>
2037
<color key="backgroundColor" systemColor="opaqueSeparatorColor"/>
38+
<constraints>
39+
<constraint firstItem="gqJ-oN-JCK" firstAttribute="top" secondItem="QCP-uk-H24" secondAttribute="top" constant="30" id="2Vg-iw-6Rl"/>
40+
<constraint firstItem="gqJ-oN-JCK" firstAttribute="centerX" secondItem="jmi-Lo-St4" secondAttribute="centerX" id="Crs-BD-puY"/>
41+
</constraints>
2142
</view>
2243
</viewController>
2344
<placeholder placeholderIdentifier="IBFirstResponder" id="Uzt-sR-4xA" sceneMemberID="firstResponder"/>
@@ -29,5 +50,8 @@
2950
<systemColor name="opaqueSeparatorColor">
3051
<color red="0.77647058820000003" green="0.77647058820000003" blue="0.7843137255" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
3152
</systemColor>
53+
<systemColor name="systemBlueColor">
54+
<color red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
55+
</systemColor>
3256
</resources>
3357
</document>

Example/ContainerControllerSwift/ExampleAddCollectionView/ExampleAddCollectionViewController.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,22 @@ class ExampleAddCollectionViewController: StoryboardController {
3131
override func viewWillAppear(_ animated: Bool) {
3232
super.viewWillAppear(animated)
3333

34+
navigationController?.navigationBar.isTranslucent = true
35+
3436
container.move(type: .middle)
3537
}
3638

39+
@IBAction func buttonChangeTranslucent(_ sender: UIButton) {
40+
41+
guard let translucent = navigationController?.navigationBar.isTranslucent else { return }
42+
43+
navigationController?.navigationBar.isTranslucent = !translucent
44+
45+
container.move(type: container.moveType)
46+
}
47+
48+
49+
3750
func addCollectionView() -> UICollectionView {
3851

3952
let layout = UICollectionViewFlowLayout()

Sources/ContainerController/ContainerController.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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,
@@ -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

0 commit comments

Comments
 (0)