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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ DerivedData
*.hmap
*.ipa
*.xcuserstate
IDEWorkspaceChecks.plist

# CocoaPods
#
Expand Down
4 changes: 4 additions & 0 deletions SpringIndicator/RefreshIndicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ open class RefreshIndicator: UIControl {
setupIndicator()
}

deinit {
stopIndicatorAnimation()
}

private func setupIndicator() {
indicator.lineWidth = 2
indicator.rotationDuration = 1
Expand Down
22 changes: 17 additions & 5 deletions SpringIndicator/SpringIndicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import UIKit

@IBDesignable
open class SpringIndicator: UIView {
deinit {
stop()
}

let indicatorView: UIView
fileprivate var pathLayer: CAShapeLayer? {
Expand Down Expand Up @@ -65,15 +62,30 @@ open class SpringIndicator: UIView {

backgroundColor = UIColor.clear
}


deinit {
stop()
}

open override func draw(_ rect: CGRect) {
super.draw(rect)

if animating {
start(for: .begin)
}
}

open override func layoutSubviews() {
super.layoutSubviews()
restartAnimationsIfNeeded()
}

private func restartAnimationsIfNeeded() {
if isSpinning {
stop()
start(for: .begin)
}
}

private func makeRotationPath(for process: AnimationProcess) -> UIBezierPath {
let start = CGFloat(process.startAngle())
let end = CGFloat(Double.pi + Double.pi_2) + start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = SpringIndicatorExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.1;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.kyoheiito.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -467,6 +468,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = SpringIndicatorExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.1;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.kyoheiito.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8191" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="0Of-Yw-92t">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="0Of-Yw-92t">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
<scene sceneID="hId-KX-iEr">
<objects>
<navigationController id="0Of-Yw-92t" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="qB6-ae-FqW">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
Expand All @@ -30,12 +34,12 @@
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="cxV-Ga-Hog" customClass="SpringIndicator" customModule="SpringIndicator">
<rect key="frame" x="250" y="250" width="100" height="100"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<rect key="frame" x="137.5" y="283.5" width="100" height="100"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="100" id="5iY-bu-uZQ"/>
<constraint firstAttribute="width" constant="100" id="YlF-Cf-0SS"/>
Expand All @@ -45,34 +49,31 @@
<userDefinedRuntimeAttribute type="number" keyPath="lineWidth">
<real key="value" value="5"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="rotateDuration">
<real key="value" value="2"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="lineColor">
<color key="value" red="0.78270415145985406" green="0.364735401459854" blue="0.46612682481751827" alpha="1" colorSpace="calibratedRGB"/>
<color key="value" red="0.78270415145985406" green="0.364735401459854" blue="0.46612682481751827" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="1uP-jp-eyP">
<rect key="frame" x="262" y="483" width="75" height="30"/>
<rect key="frame" x="150.5" y="550" width="74" height="30"/>
<state key="normal" title="Table View">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<segue destination="Z8a-AL-V35" kind="show" id="ktE-cz-wN8"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="FyS-Y5-YT3">
<rect key="frame" x="266" y="533" width="68" height="30"/>
<rect key="frame" x="153.5" y="600" width="68" height="30"/>
<state key="normal" title="Web View">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<segue destination="Cvf-En-Cvv" kind="show" id="vLY-xo-IAz"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="centerX" secondItem="cxV-Ga-Hog" secondAttribute="centerX" id="9QD-EB-OB2"/>
<constraint firstAttribute="centerX" secondItem="FyS-Y5-YT3" secondAttribute="centerX" id="BTE-Uq-MVR"/>
Expand All @@ -86,6 +87,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-354" y="1002"/>
</scene>
<!--Web View Controller-->
<scene sceneID="8H5-fP-CM2">
Expand All @@ -96,18 +98,18 @@
<viewControllerLayoutGuide type="bottom" id="kFl-W5-vxs"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="sMd-SK-fwi">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<webView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="gqD-ZS-zcv">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<outlet property="delegate" destination="Cvf-En-Cvv" id="0gw-Cm-wEZ"/>
</connections>
</webView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="gqD-ZS-zcv" firstAttribute="top" secondItem="sMd-SK-fwi" secondAttribute="top" id="B7U-dK-JSC"/>
<constraint firstItem="kFl-W5-vxs" firstAttribute="top" secondItem="gqD-ZS-zcv" secondAttribute="bottom" id="NqG-JT-7rz"/>
Expand All @@ -132,15 +134,15 @@
<viewControllerLayoutGuide type="bottom" id="bOD-en-piK"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="yND-me-yZp">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO" id="DGh-mv-smJ">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</tableView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="DGh-mv-smJ" secondAttribute="trailing" id="0XV-8O-pJz"/>
<constraint firstItem="bOD-en-piK" firstAttribute="top" secondItem="DGh-mv-smJ" secondAttribute="bottom" id="2St-Mc-k2c"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@ import UIKit
import SpringIndicator

class TableViewController: UIViewController {

@IBOutlet weak var tableView: UITableView!

let refreshControl = RefreshIndicator()

let dataSourceList: [[String]] = [[Int](0..<20).map({ "section 0, cell \($0)" })]

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

tableView.dataSource = self
tableView.delegate = self

tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")

refreshControl.addTarget(self, action: #selector(TableViewController.onRefresh), for: .valueChanged)

tableView.addSubview(refreshControl)
}

@objc func onRefresh() {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
self.refreshControl.endRefreshing()
Expand Down
22 changes: 15 additions & 7 deletions SpringIndicatorExample/SpringIndicatorExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,25 @@ class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

let defaultIndicator = SpringIndicator(frame: CGRect(x: 100, y: 100, width: 60, height: 60))
defaultIndicator.lineColors = [.red, .blue, .orange, .green]
defaultIndicator.rotationDuration = 2
defaultIndicator.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(defaultIndicator)

let topAnchor: NSLayoutYAxisAnchor
if #available(iOS 11.0, *) {
topAnchor = view.safeAreaLayoutGuide.topAnchor
} else {
topAnchor = topLayoutGuide.topAnchor
}

NSLayoutConstraint.activate([
defaultIndicator.topAnchor.constraint(equalTo: topAnchor, constant: 40),
defaultIndicator.centerXAnchor.constraint(equalTo: view.centerXAnchor),
defaultIndicator.heightAnchor.constraint(equalToConstant: 40),
defaultIndicator.widthAnchor.constraint(equalToConstant: 40),
])
defaultIndicator.start()

let colorIndicator = SpringIndicator(frame: CGRect(x: 300, y: 100, width: 20, height: 20))
Expand All @@ -29,9 +42,4 @@ class ViewController: UIViewController {
colorIndicator.start()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}