Skip to content

Commit

Permalink
example project
Browse files Browse the repository at this point in the history
  • Loading branch information
jcavar committed Aug 2, 2015
1 parent d56f016 commit 687f3d4
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 68 deletions.
30 changes: 25 additions & 5 deletions PullToRefresh.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
C7AC6CFC19A894DF007107DF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7AC6CF619A894DF007107DF /* AppDelegate.swift */; };
C7AC6CFD19A894DF007107DF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C7AC6CF719A894DF007107DF /* Main.storyboard */; };
C7AC6CFE19A894DF007107DF /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C7AC6CF919A894DF007107DF /* Images.xcassets */; };
C7AC6D0019A894DF007107DF /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7AC6CFB19A894DF007107DF /* ViewController.swift */; };
C7AC6D0019A894DF007107DF /* PullToRefreshViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7AC6CFB19A894DF007107DF /* PullToRefreshViewController.swift */; };
C7AEDC171B6D53D100E09098 /* ChooseModeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7AEDC161B6D53D100E09098 /* ChooseModeViewController.swift */; };
C7B53A431AC996B80021914B /* CustomSubview.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7B53A421AC996B80021914B /* CustomSubview.swift */; };
C7B53A451AC9971C0021914B /* CustomSubview.xib in Resources */ = {isa = PBXBuildFile; fileRef = C7B53A441AC9971C0021914B /* CustomSubview.xib */; };
C7DA91CD19B31B7C00C4012B /* Animator.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7DA91CC19B31B7C00C4012B /* Animator.swift */; };
Expand Down Expand Up @@ -84,7 +85,8 @@
C7AC6CF819A894DF007107DF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
C7AC6CF919A894DF007107DF /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
C7AC6CFA19A894DF007107DF /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C7AC6CFB19A894DF007107DF /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
C7AC6CFB19A894DF007107DF /* PullToRefreshViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PullToRefreshViewController.swift; sourceTree = "<group>"; };
C7AEDC161B6D53D100E09098 /* ChooseModeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChooseModeViewController.swift; sourceTree = "<group>"; };
C7B53A421AC996B80021914B /* CustomSubview.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomSubview.swift; sourceTree = "<group>"; };
C7B53A441AC9971C0021914B /* CustomSubview.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CustomSubview.xib; sourceTree = "<group>"; };
C7D1CF8F199BB3C8009FD485 /* PullToRefreshDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PullToRefreshDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -168,16 +170,33 @@
isa = PBXGroup;
children = (
C7AC6CF619A894DF007107DF /* AppDelegate.swift */,
C7AC6CFB19A894DF007107DF /* ViewController.swift */,
C7AEDC181B6D53DA00E09098 /* ViewController */,
C7AC6CF719A894DF007107DF /* Main.storyboard */,
C7AC6CF919A894DF007107DF /* Images.xcassets */,
C7956A3D19A8966400CF6484 /* Supporting Files */,
C7AEDC191B6D53E000E09098 /* Animator */,
);
path = PullToRefreshDemo;
sourceTree = "<group>";
};
C7AEDC181B6D53DA00E09098 /* ViewController */ = {
isa = PBXGroup;
children = (
C7AC6CFB19A894DF007107DF /* PullToRefreshViewController.swift */,
C7AEDC161B6D53D100E09098 /* ChooseModeViewController.swift */,
);
name = ViewController;
sourceTree = "<group>";
};
C7AEDC191B6D53E000E09098 /* Animator */ = {
isa = PBXGroup;
children = (
C7A355A119B612D5000DDC72 /* BeatAnimator.swift */,
C7A355D019B62125000DDC72 /* PacmanAnimator.swift */,
C7B53A421AC996B80021914B /* CustomSubview.swift */,
C7B53A441AC9971C0021914B /* CustomSubview.xib */,
);
path = PullToRefreshDemo;
name = Animator;
sourceTree = "<group>";
};
C7D1CF86199BB3C8009FD485 = {
Expand Down Expand Up @@ -368,8 +387,9 @@
files = (
C7A355D119B62125000DDC72 /* PacmanAnimator.swift in Sources */,
C7B53A431AC996B80021914B /* CustomSubview.swift in Sources */,
C7AC6D0019A894DF007107DF /* ViewController.swift in Sources */,
C7AC6D0019A894DF007107DF /* PullToRefreshViewController.swift in Sources */,
C7AC6CFC19A894DF007107DF /* AppDelegate.swift in Sources */,
C7AEDC171B6D53D100E09098 /* ChooseModeViewController.swift in Sources */,
C7A355A219B612D5000DDC72 /* BeatAnimator.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
79 changes: 73 additions & 6 deletions PullToRefreshDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="RWb-co-Zty">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14E46" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="RWb-co-Zty">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
</dependencies>
Expand All @@ -14,27 +14,94 @@
<color key="barTintColor" red="0.96862751245498657" green="0.96862751245498657" blue="0.96862751245498657" alpha="1" colorSpace="deviceRGB"/>
</navigationBar>
<connections>
<segue destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController" id="UhW-aa-ZwF"/>
<segue destination="RFH-zq-9gR" kind="relationship" relationship="rootViewController" id="WGV-CK-QNn"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Vwd-RL-BVZ" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-655" y="59"/>
</scene>
<!--Choose Mode View Controller-->
<scene sceneID="oAy-Hl-ycD">
<objects>
<viewController id="RFH-zq-9gR" customClass="ChooseModeViewController" customModule="PullToRefreshDemo" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Jwa-dH-WnZ"/>
<viewControllerLayoutGuide type="bottom" id="WkW-1z-Uxh"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="SeT-4b-Nhw">
<rect key="frame" x="0.0" y="0.0" width="320" height="504"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="8ef-eQ-bwJ">
<rect key="frame" x="144" y="96" width="32" height="30"/>
<state key="normal" title="Beat">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="beatAction:" destination="RFH-zq-9gR" eventType="touchUpInside" id="j1e-Ug-Hw7"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Phb-fN-T5w">
<rect key="frame" x="132" y="134" width="56" height="30"/>
<state key="normal" title="Pacman">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="pacmanAction:" destination="RFH-zq-9gR" eventType="touchUpInside" id="aK3-Na-Pco"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Bnx-XC-RaR">
<rect key="frame" x="133" y="172" width="54" height="30"/>
<state key="normal" title="Custom">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="customAction:" destination="RFH-zq-9gR" eventType="touchUpInside" id="LfN-aH-EiW"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="h5G-X9-Qyf">
<rect key="frame" x="136" y="58" width="49" height="30"/>
<state key="normal" title="Default">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="defaultAction:" destination="RFH-zq-9gR" eventType="touchUpInside" id="vuF-tC-pFA"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="centerX" secondItem="Phb-fN-T5w" secondAttribute="centerX" id="PCV-Gn-Hr1"/>
<constraint firstAttribute="centerX" secondItem="8ef-eQ-bwJ" secondAttribute="centerX" id="age-3w-nqf"/>
<constraint firstAttribute="centerX" secondItem="Bnx-XC-RaR" secondAttribute="centerX" id="b7p-mx-ov2"/>
<constraint firstItem="8ef-eQ-bwJ" firstAttribute="top" secondItem="h5G-X9-Qyf" secondAttribute="bottom" constant="8" id="d05-jf-IhB"/>
<constraint firstItem="h5G-X9-Qyf" firstAttribute="top" secondItem="Jwa-dH-WnZ" secondAttribute="bottom" constant="58" id="eMs-2s-g1f"/>
<constraint firstItem="Bnx-XC-RaR" firstAttribute="top" secondItem="Phb-fN-T5w" secondAttribute="bottom" constant="8" id="mTB-9E-ci7"/>
<constraint firstItem="Phb-fN-T5w" firstAttribute="top" secondItem="8ef-eQ-bwJ" secondAttribute="bottom" constant="8" id="u0s-Uu-qxY"/>
<constraint firstAttribute="centerX" secondItem="h5G-X9-Qyf" secondAttribute="centerX" id="wpB-gj-h9z"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="o92-TZ-fbq"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="V7h-TM-QaQ" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-243" y="59"/>
</scene>
<!--Pull to refresh example-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="PullToRefreshDemo" customModuleProvider="target" sceneMemberID="viewController">
<viewController storyboardIdentifier="PullToRefreshViewController" id="BYZ-38-t0r" customClass="PullToRefreshViewController" customModule="PullToRefreshDemo" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Da1-dG-drI"/>
<viewControllerLayoutGuide type="bottom" id="Uca-LH-LIW"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="320" height="504"/>
<rect key="frame" x="0.0" y="64" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="60" sectionHeaderHeight="22" sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO" id="h8l-ma-AYT">
<rect key="frame" x="0.0" y="0.0" width="320" height="504"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<sections/>
<connections>
Expand All @@ -57,7 +124,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-97" y="59"/>
<point key="canvasLocation" x="124" y="59"/>
</scene>
</scenes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
Expand Down
10 changes: 1 addition & 9 deletions PullToRefreshDemo/BeatAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class BeatAnimator: UIView, PullToRefreshViewDelegate {
private let layerSeparator = CAShapeLayer()

override init(frame: CGRect) {

super.init(frame: frame)

layerLoader.lineWidth = 4
Expand All @@ -48,7 +47,6 @@ class BeatAnimator: UIView, PullToRefreshViewDelegate {
}

func pullToRefresh(view: PullToRefreshView, progressDidChange progress: CGFloat) {

layerLoader.strokeEnd = progress
}

Expand All @@ -57,13 +55,10 @@ class BeatAnimator: UIView, PullToRefreshViewDelegate {
}

func pullToRefreshAnimationDidEnd(view: PullToRefreshView) {

layerLoader.removeAllAnimations()

}

func pullToRefreshAnimationDidStart(view: PullToRefreshView) {

let pathAnimationEnd = CABasicAnimation(keyPath: "strokeEnd")
pathAnimationEnd.duration = 0.5
pathAnimationEnd.repeatCount = 100
Expand All @@ -82,17 +77,14 @@ class BeatAnimator: UIView, PullToRefreshViewDelegate {
}

override func layoutSubviews() {

super.layoutSubviews()

if let superview = superview {
if layerLoader.superlayer == nil {
superview.layer.addSublayer(layerSeparator)
superview.layer.addSublayer(layerLoader)
}
if layerSeparator.superlayer == nil {
superview.layer.addSublayer(layerSeparator)
}

let bezierPathLoader = UIBezierPath()
bezierPathLoader.moveToPoint(CGPointMake(0, superview.frame.height - 3))
bezierPathLoader.addLineToPoint(CGPoint(x: superview.frame.width, y: superview.frame.height - 3))
Expand Down
46 changes: 46 additions & 0 deletions PullToRefreshDemo/ChooseModeViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// ChooseModeViewController.swift
// PullToRefresh
//
// Created by Josip Cavar on 01/08/15.
// Copyright (c) 2015 Josip Cavar. All rights reserved.
//

import UIKit

class ChooseModeViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
}

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

@IBAction func defaultAction(sender: AnyObject) {
showControllerWithMode(.Default)
}

@IBAction func beatAction(sender: AnyObject) {
showControllerWithMode(.Beat)
}

@IBAction func pacmanAction(sender: AnyObject) {
showControllerWithMode(.Pacman)
}

@IBAction func customAction(sender: AnyObject) {
showControllerWithMode(.Custom)
}

func showControllerWithMode(mode: ExampleMode) {
if let pullToRefreshViewControler = self.storyboard?.instantiateViewControllerWithIdentifier("PullToRefreshViewController") as? PullToRefreshViewController {
pullToRefreshViewControler.exampleMode = mode
navigationController?.pushViewController(pullToRefreshViewControler, animated: true)
}
}
}
3 changes: 0 additions & 3 deletions PullToRefreshDemo/CustomSubview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ class CustomSubview: UIView, PullToRefreshViewDelegate {
@IBOutlet weak var activityIndicator: UIActivityIndicatorView!
@IBOutlet weak var labelTitle: UILabel!


func pullToRefreshAnimationDidStart(view: PullToRefreshView) {

activityIndicator.startAnimating()
labelTitle.text = "Loading"
}

func pullToRefreshAnimationDidEnd(view: PullToRefreshView) {

activityIndicator.stopAnimating()
labelTitle.text = ""
}
Expand Down
7 changes: 0 additions & 7 deletions PullToRefreshDemo/PacmanAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class PacmanAnimator: UIView, PullToRefreshViewDelegate {
private let layerSeparator = CAShapeLayer()

override init(frame: CGRect) {

super.init(frame: frame)

layerLoader.lineWidth = 8
Expand All @@ -50,7 +49,6 @@ class PacmanAnimator: UIView, PullToRefreshViewDelegate {
}

func pullToRefresh(view: PullToRefreshView, progressDidChange progress: CGFloat) {

layerLoader.strokeEnd = progress
}

Expand All @@ -59,13 +57,10 @@ class PacmanAnimator: UIView, PullToRefreshViewDelegate {
}

func pullToRefreshAnimationDidEnd(view: PullToRefreshView) {

layerLoader.removeAllAnimations()

}

func pullToRefreshAnimationDidStart(view: PullToRefreshView) {

let pathAnimationEnd = CABasicAnimation(keyPath: "strokeEnd")
pathAnimationEnd.duration = 0.5
pathAnimationEnd.repeatCount = 100
Expand All @@ -84,9 +79,7 @@ class PacmanAnimator: UIView, PullToRefreshViewDelegate {
}

override func layoutSubviews() {

super.layoutSubviews()

if let superview = superview {
if layerSeparator.superlayer == nil {
superview.layer.addSublayer(layerSeparator)
Expand Down
Loading

0 comments on commit 687f3d4

Please sign in to comment.