Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
ngochiencse committed Jun 1, 2021
1 parent 713d24c commit 212ee83
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 130 deletions.
24 changes: 12 additions & 12 deletions Example/HPParallaxHeader.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
0E46870B26591CFE00804379 /* UIScrollViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E4687052658F3A700804379 /* UIScrollViewExample.swift */; };
0E7234092665F5A900134D4E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0E7234072665F5A900134D4E /* LaunchScreen.storyboard */; };
0E8714CF2657BD5800327BD1 /* StarshipHeader.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0E8714CE2657BD5800327BD1 /* StarshipHeader.xib */; };
0E8714D12657BD8200327BD1 /* MXScrollViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E8714D02657BD8200327BD1 /* MXScrollViewExample.swift */; };
0EBD4A6C265A0C3200798655 /* MXFalconViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EBD4A6B265A0C3200798655 /* MXFalconViewController.swift */; };
0EBD4A6E265A0CEF00798655 /* MXWebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EBD4A6D265A0CEF00798655 /* MXWebViewController.swift */; };
0E8714D12657BD8200327BD1 /* HPScrollViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E8714D02657BD8200327BD1 /* HPScrollViewExample.swift */; };
0EBD4A6C265A0C3200798655 /* HPFalconViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EBD4A6B265A0C3200798655 /* HPFalconViewController.swift */; };
0EBD4A6E265A0CEF00798655 /* HPWebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EBD4A6D265A0CEF00798655 /* HPWebViewController.swift */; };
3046F83DA72E20F5285F56B7 /* Pods_HPParallaxHeader_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B0AD6A27F03E2F5768320095 /* Pods_HPParallaxHeader_Example.framework */; };
54340CAAD83E77CA444DA693 /* Pods_HPParallaxHeader_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 693FA2B4E17A92C1B32B5739 /* Pods_HPParallaxHeader_Tests.framework */; };
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; };
Expand All @@ -36,9 +36,9 @@
0E4687052658F3A700804379 /* UIScrollViewExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIScrollViewExample.swift; sourceTree = "<group>"; };
0E7234082665F5A900134D4E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
0E8714CE2657BD5800327BD1 /* StarshipHeader.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = StarshipHeader.xib; sourceTree = "<group>"; };
0E8714D02657BD8200327BD1 /* MXScrollViewExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MXScrollViewExample.swift; sourceTree = "<group>"; };
0EBD4A6B265A0C3200798655 /* MXFalconViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MXFalconViewController.swift; sourceTree = "<group>"; };
0EBD4A6D265A0CEF00798655 /* MXWebViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MXWebViewController.swift; sourceTree = "<group>"; };
0E8714D02657BD8200327BD1 /* HPScrollViewExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HPScrollViewExample.swift; sourceTree = "<group>"; };
0EBD4A6B265A0C3200798655 /* HPFalconViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HPFalconViewController.swift; sourceTree = "<group>"; };
0EBD4A6D265A0CEF00798655 /* HPWebViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HPWebViewController.swift; sourceTree = "<group>"; };
358ADADFEC650AAB3B0D1EEE /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
43E192DCC80B3DB314273F2D /* Pods-HPParallaxHeader_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HPParallaxHeader_Example.release.xcconfig"; path = "Target Support Files/Pods-HPParallaxHeader_Example/Pods-HPParallaxHeader_Example.release.xcconfig"; sourceTree = "<group>"; };
607FACD01AFB9204008FA782 /* HPParallaxHeader_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HPParallaxHeader_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -115,9 +115,9 @@
607FACD51AFB9204008FA782 /* AppDelegate.swift */,
607FACD71AFB9204008FA782 /* ViewController.swift */,
0E4687052658F3A700804379 /* UIScrollViewExample.swift */,
0E8714D02657BD8200327BD1 /* MXScrollViewExample.swift */,
0EBD4A6B265A0C3200798655 /* MXFalconViewController.swift */,
0EBD4A6D265A0CEF00798655 /* MXWebViewController.swift */,
0E8714D02657BD8200327BD1 /* HPScrollViewExample.swift */,
0EBD4A6B265A0C3200798655 /* HPFalconViewController.swift */,
0EBD4A6D265A0CEF00798655 /* HPWebViewController.swift */,
607FACD91AFB9204008FA782 /* Main.storyboard */,
0E7234072665F5A900134D4E /* LaunchScreen.storyboard */,
0E8714CE2657BD5800327BD1 /* StarshipHeader.xib */,
Expand Down Expand Up @@ -347,11 +347,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0EBD4A6E265A0CEF00798655 /* MXWebViewController.swift in Sources */,
0EBD4A6E265A0CEF00798655 /* HPWebViewController.swift in Sources */,
0E46870B26591CFE00804379 /* UIScrollViewExample.swift in Sources */,
0EBD4A6C265A0C3200798655 /* MXFalconViewController.swift in Sources */,
0EBD4A6C265A0C3200798655 /* HPFalconViewController.swift in Sources */,
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */,
0E8714D12657BD8200327BD1 /* MXScrollViewExample.swift in Sources */,
0E8714D12657BD8200327BD1 /* HPScrollViewExample.swift in Sources */,
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
32 changes: 15 additions & 17 deletions Example/HPParallaxHeader/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="gJ1-TG-u0D">
<device id="retina5_5" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
Expand All @@ -14,20 +12,20 @@
<objects>
<tableViewController id="5wP-tC-L4h" customClass="UIScrollViewExample" customModule="HPParallaxHeader_Example" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="66" sectionHeaderHeight="28" sectionFooterHeight="28" id="rFe-ya-cfR">
<rect key="frame" x="0.0" y="0.0" width="414" height="687"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.99607843137254903" green="0.99215686274509807" blue="0.94117647058823528" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="separatorColor" red="0.99607843137254903" green="0.99215686274509807" blue="0.94117647058823528" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" textLabel="pgl-bc-CYS" style="IBUITableViewCellStyleDefault" id="mIY-YQ-MPX">
<rect key="frame" x="0.0" y="24.333333969116211" width="414" height="66"/>
<rect key="frame" x="0.0" y="24.5" width="600" height="66"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="mIY-YQ-MPX" id="SUD-k0-U59">
<rect key="frame" x="0.0" y="0.0" width="414" height="66"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="66"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="pgl-bc-CYS">
<rect key="frame" x="20" y="0.0" width="374" height="66"/>
<rect key="frame" x="20" y="0.0" width="560" height="66"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" red="0.058823529409999999" green="0.1019607843" blue="0.2156862745" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
Expand Down Expand Up @@ -88,7 +86,7 @@
<objects>
<viewController extendedLayoutIncludesOpaqueBars="YES" id="wpI-o5-ONu" customClass="HPScrollViewController" customModule="HPParallaxHeader" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="jJk-lh-dPo">
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<viewLayoutGuide key="safeArea" id="6c2-ZJ-CLn"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
Expand All @@ -111,27 +109,27 @@
<!--MXScrollView-->
<scene sceneID="Wus-Wb-PlD">
<objects>
<viewController restorationIdentifier="MXScrollView" id="ft2-aT-thd" customClass="MXScrollViewExample" customModule="HPParallaxHeader_Example" customModuleProvider="target" sceneMemberID="viewController">
<viewController restorationIdentifier="MXScrollView" id="ft2-aT-thd" customClass="HPScrollViewExample" customModule="HPParallaxHeader_Example" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="vbU-g6-y3Y">
<rect key="frame" x="0.0" y="0.0" width="414" height="687"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="zAk-je-ZPQ" customClass="HPScrollView" customModule="HPParallaxHeader">
<rect key="frame" x="0.0" y="0.0" width="414" height="687"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="551"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="mdO-DV-sOC">
<rect key="frame" x="0.0" y="0.0" width="414" height="687"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="551"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="2DF-tw-JRW">
<rect key="frame" x="0.0" y="0.0" width="200.66666666666666" height="687"/>
<rect key="frame" x="0.0" y="0.0" width="290.5" height="551"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<connections>
<outlet property="dataSource" destination="ft2-aT-thd" id="KBH-89-BC2"/>
<outlet property="delegate" destination="ft2-aT-thd" id="zVP-68-K4o"/>
</connections>
</tableView>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="NNy-t1-9RU">
<rect key="frame" x="200.66666666666663" y="0.0" width="213.33333333333337" height="687"/>
<rect key="frame" x="290.5" y="0.0" width="309.5" height="551"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<connections>
<outlet property="dataSource" destination="ft2-aT-thd" id="4Cb-rZ-njK"/>
Expand Down Expand Up @@ -188,13 +186,13 @@
<!--Web View Controller-->
<scene sceneID="e88-UT-JKL">
<objects>
<viewController id="erx-Ha-mfa" customClass="MXWebViewController" customModule="HPParallaxHeader_Example" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="erx-Ha-mfa" customClass="HPWebViewController" customModule="HPParallaxHeader_Example" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="vPo-vc-HEb">
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<wkWebView contentMode="scaleToFill" allowsBackForwardNavigationGestures="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vWq-uf-ZaW">
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<color key="backgroundColor" red="0.36078431370000003" green="0.38823529410000002" blue="0.4039215686" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<wkWebViewConfiguration key="configuration">
<audiovisualMediaTypes key="mediaTypesRequiringUserActionForPlayback" none="YES"/>
Expand Down Expand Up @@ -242,7 +240,7 @@
<!--Falcon View Controller-->
<scene sceneID="ROx-wQ-jV4">
<objects>
<viewController id="c12-C7-n3f" customClass="MXFalconViewController" customModule="HPParallaxHeader_Example" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="c12-C7-n3f" customClass="HPFalconViewController" customModule="HPParallaxHeader_Example" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="gU8-90-gva">
<rect key="frame" x="0.0" y="0.0" width="375" height="300"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down
29 changes: 29 additions & 0 deletions Example/HPParallaxHeader/HPFalconViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// HPFalconViewController.swift
// HPParallaxHeader
//
// Created by Hien Pham on 03/04/2021.
// Copyright (c) 2021 Hien Pham. All rights reserved.
//

import UIKit
import HPParallaxHeader

class HPFalconViewController: UIViewController, HPParallaxHeaderDelegate {

@IBOutlet weak var falcon: UIImageView!

override func viewDidLoad() {
super.viewDidLoad()

parallaxHeader?.delegate = self
}

// MARK: - MXParallaxHeaderDelegate

func parallaxHeaderDidScroll(_ parallaxHeader: HPParallaxHeader) {
let angle = parallaxHeader.progress * CGFloat(Double.pi) * 2
self.falcon.transform = CGAffineTransform.identity.rotated(by: angle)
}

}
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
// MXScrollViewExample.swift
//
// Copyright (c) 2019 Maxime Epain
// HPScrollViewExample.swift
// HPParallaxHeader
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// Created by Hien Pham on 03/04/2021.
// Copyright (c) 2021 Hien Pham. All rights reserved.
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import UIKit
import HPParallaxHeader

class MXScrollViewExample: UIViewController, UITableViewDelegate, UITableViewDataSource {
class HPScrollViewExample: UIViewController, UITableViewDelegate, UITableViewDataSource {

fileprivate var SpanichWhite : UIColor = #colorLiteral(red: 0.9960784314, green: 0.9921568627, blue: 0.9411764706, alpha: 1) // #FEFDF0

Expand Down Expand Up @@ -62,6 +48,6 @@ class MXScrollViewExample: UIViewController, UITableViewDelegate, UITableViewDat
// MARK: - Scroll view delegate

func scrollViewDidScroll(_ scrollView: UIScrollView) {
NSLog("progress %f", scrollView.parallaxHeader.progress ?? 0)
print("progress \(scrollView.parallaxHeader.progress)")
}
}
23 changes: 23 additions & 0 deletions Example/HPParallaxHeader/HPWebViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// HPWebViewController.swift
// HPParallaxHeader
//
// Created by Hien Pham on 03/04/2021.
// Copyright (c) 2021 Hien Pham. All rights reserved.
//

import UIKit
import WebKit
import HPParallaxHeader

class HPWebViewController: UIViewController {

@IBOutlet weak var webView: WKWebView!

override func viewDidLoad() {
super.viewDidLoad()

let request = URLRequest(url: URL(string: "https://dribbble.com/search?q=spaceship")!)
webView.load(request)
}
}
Loading

0 comments on commit 212ee83

Please sign in to comment.