Skip to content

Commit

Permalink
Version 2.2 - Animated Content Views
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Kluz committed Sep 27, 2015
1 parent b83a756 commit 55f5efa
Show file tree
Hide file tree
Showing 13 changed files with 334 additions and 187 deletions.
40 changes: 9 additions & 31 deletions Demo/DemoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,21 @@ class DemoViewController: UIViewController {
PKHUD.sharedHUD.dimsBackground = false
PKHUD.sharedHUD.userInteractionOnUnderlyingViewsEnabled = false
}

@IBAction func showStatusHUD(sender: AnyObject) {
PKHUD.sharedHUD.contentView = PKHUDStatusView(title: "Success", subtitle: "Subtitle", image: PKHUDAssets.checkmarkImage)
PKHUD.sharedHUD.show()
PKHUD.sharedHUD.hide(afterDelay: 2.0)
}

@IBAction func showProgressHUD(sender: AnyObject) {
PKHUD.sharedHUD.contentView = PKHUDProgressView()
PKHUD.sharedHUD.show()
PKHUD.sharedHUD.hide(afterDelay: 2.0)
}

@IBAction func showAppleProgressHUD(sender: AnyObject) {
PKHUD.sharedHUD.contentView = PKHUDSystemActivityIndicatorView()

@IBAction func showAnimatedSuccessHUD(sender: AnyObject) {
PKHUD.sharedHUD.contentView = PKHUDSuccessView()
PKHUD.sharedHUD.show()
PKHUD.sharedHUD.hide(afterDelay: 2.0)
PKHUD.sharedHUD.hide(afterDelay: 2.0);
}

@IBAction func showTitleHUD(sender: AnyObject) {
PKHUD.sharedHUD.contentView = PKHUDTitleView(title: "Success", image: PKHUDAssets.checkmarkImage)
@IBAction func showAnimatedErrorHUD(sender: AnyObject) {
PKHUD.sharedHUD.contentView = PKHUDErrorAnimation()
PKHUD.sharedHUD.show()
PKHUD.sharedHUD.hide(afterDelay: 2.0)
PKHUD.sharedHUD.hide(afterDelay: 2.0);
}

@IBAction func showSubtitleHUD(sender: AnyObject) {
PKHUD.sharedHUD.contentView = PKHUDSubtitleView(subtitle: "Error", image: PKHUDAssets.crossImage)
@IBAction func showAnimatedProgressHUD(sender: AnyObject) {
PKHUD.sharedHUD.contentView = PKHUDProgressView()
PKHUD.sharedHUD.show()
PKHUD.sharedHUD.hide(afterDelay: 2.0)
}
Expand All @@ -53,16 +41,6 @@ class DemoViewController: UIViewController {
PKHUD.sharedHUD.hide(afterDelay: 2.0)
}

@IBAction func showAlertWithHUD(sender: AnyObject) {
let alert = UIAlertController(title: "An Alert", message: "With an Extraordinary Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(0.25 * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) {
self.showTitleHUD(sender)
}
}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.AllButUpsideDown;
}
Expand Down
4 changes: 2 additions & 2 deletions Demo/Launch Screen.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8121.17" systemVersion="15A178w" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8191" systemVersion="15A282b" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.14"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand Down
99 changes: 36 additions & 63 deletions Demo/Storyboard.storyboard

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion PKHUD.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = 'PKHUD'
s.module_name = 'PKHUD'
s.version = '2.1.0'
s.version = '2.2.0'
s.summary = 'A Swift based reimplementation of the Apple HUD (Volume, Ringer, Rotation,…) for iOS 8'
s.homepage = 'https://github.com/pkluz/PKHUD'
s.license = 'MIT'
Expand Down
38 changes: 29 additions & 9 deletions PKHUD.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
objects = {

/* Begin PBXBuildFile section */
F908BEC01BB849290015E5A8 /* PKHUDSuccessView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F908BEBF1BB849290015E5A8 /* PKHUDSuccessView.swift */; settings = {ASSET_TAGS = (); }; };
F908BEC31BB84D0B0015E5A8 /* PKHUDAnimating.swift in Sources */ = {isa = PBXBuildFile; fileRef = F908BEC21BB84D0B0015E5A8 /* PKHUDAnimating.swift */; settings = {ASSET_TAGS = (); }; };
F908BEC51BB852C60015E5A8 /* PKHUDErrorAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = F908BEC41BB852C60015E5A8 /* PKHUDErrorAnimation.swift */; settings = {ASSET_TAGS = (); }; };
F908BEC81BB85EA70015E5A8 /* PKHUDProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F908BEC71BB85EA70015E5A8 /* PKHUDProgressView.swift */; settings = {ASSET_TAGS = (); }; };
F935B1581B2B8088003C3734 /* Storyboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F935B1571B2B8088003C3734 /* Storyboard.storyboard */; };
F935B15A1B2B865A003C3734 /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F935B1591B2B865A003C3734 /* Launch Screen.storyboard */; };
F935B15D1B2B8C20003C3734 /* PKHUDSquareBaseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F935B15C1B2B8C20003C3734 /* PKHUDSquareBaseView.swift */; };
F935B15F1B2B8C7E003C3734 /* PKHUDWideBaseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F935B15E1B2B8C7E003C3734 /* PKHUDWideBaseView.swift */; };
F935B1611B2B8C8E003C3734 /* PKHUDTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F935B1601B2B8C8E003C3734 /* PKHUDTextView.swift */; };
F935B1631B2B8CE2003C3734 /* PKHUDImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F935B1621B2B8CE2003C3734 /* PKHUDImageView.swift */; };
F935B1651B2B8D0A003C3734 /* PKHUDProgressVIew.swift in Sources */ = {isa = PBXBuildFile; fileRef = F935B1641B2B8D0A003C3734 /* PKHUDProgressVIew.swift */; };
F935B1671B2B8D8C003C3734 /* PKHUDSystemActivityIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F935B1661B2B8D8C003C3734 /* PKHUDSystemActivityIndicatorView.swift */; };
F935B1691B2B8E10003C3734 /* PKHUDTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F935B1681B2B8E10003C3734 /* PKHUDTitleView.swift */; };
F935B16B1B2B8EA6003C3734 /* PKHUDSubtitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F935B16A1B2B8EA6003C3734 /* PKHUDSubtitleView.swift */; };
F935B16D1B2B8F8B003C3734 /* PKHUDStatusVIew.swift in Sources */ = {isa = PBXBuildFile; fileRef = F935B16C1B2B8F8B003C3734 /* PKHUDStatusVIew.swift */; };
F935B16D1B2B8F8B003C3734 /* PKHUDStatusView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F935B16C1B2B8F8B003C3734 /* PKHUDStatusView.swift */; };
F996320219514FAC001F73CA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F996320119514FAC001F73CA /* AppDelegate.swift */; };
F996320419514FAD001F73CA /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F996320319514FAD001F73CA /* Images.xcassets */; };
F996322319514FD8001F73CA /* PKHUD.h in Headers */ = {isa = PBXBuildFile; fileRef = F996322219514FD8001F73CA /* PKHUD.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -64,17 +67,20 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
F908BEBF1BB849290015E5A8 /* PKHUDSuccessView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDSuccessView.swift; sourceTree = "<group>"; };
F908BEC21BB84D0B0015E5A8 /* PKHUDAnimating.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDAnimating.swift; sourceTree = "<group>"; };
F908BEC41BB852C60015E5A8 /* PKHUDErrorAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDErrorAnimation.swift; sourceTree = "<group>"; };
F908BEC71BB85EA70015E5A8 /* PKHUDProgressView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDProgressView.swift; sourceTree = "<group>"; };
F935B1571B2B8088003C3734 /* Storyboard.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Storyboard.storyboard; sourceTree = "<group>"; };
F935B1591B2B865A003C3734 /* Launch Screen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = "<group>"; };
F935B15C1B2B8C20003C3734 /* PKHUDSquareBaseView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDSquareBaseView.swift; sourceTree = "<group>"; };
F935B15E1B2B8C7E003C3734 /* PKHUDWideBaseView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDWideBaseView.swift; sourceTree = "<group>"; };
F935B1601B2B8C8E003C3734 /* PKHUDTextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDTextView.swift; sourceTree = "<group>"; };
F935B1621B2B8CE2003C3734 /* PKHUDImageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDImageView.swift; sourceTree = "<group>"; };
F935B1641B2B8D0A003C3734 /* PKHUDProgressVIew.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDProgressVIew.swift; sourceTree = "<group>"; };
F935B1661B2B8D8C003C3734 /* PKHUDSystemActivityIndicatorView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDSystemActivityIndicatorView.swift; sourceTree = "<group>"; };
F935B1681B2B8E10003C3734 /* PKHUDTitleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDTitleView.swift; sourceTree = "<group>"; };
F935B16A1B2B8EA6003C3734 /* PKHUDSubtitleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDSubtitleView.swift; sourceTree = "<group>"; };
F935B16C1B2B8F8B003C3734 /* PKHUDStatusVIew.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDStatusVIew.swift; sourceTree = "<group>"; };
F935B16C1B2B8F8B003C3734 /* PKHUDStatusView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDStatusView.swift; sourceTree = "<group>"; };
F99631FC19514FAC001F73CA /* PKHUD Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "PKHUD Demo.app"; sourceTree = BUILT_PRODUCTS_DIR; };
F996320019514FAC001F73CA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F996320119514FAC001F73CA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -110,18 +116,29 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
F908BEC11BB84D010015E5A8 /* Protocol */ = {
isa = PBXGroup;
children = (
F908BEC21BB84D0B0015E5A8 /* PKHUDAnimating.swift */,
);
name = Protocol;
sourceTree = "<group>";
};
F935B15B1B2B8C03003C3734 /* Content Views */ = {
isa = PBXGroup;
children = (
F908BEC11BB84D010015E5A8 /* Protocol */,
F935B15C1B2B8C20003C3734 /* PKHUDSquareBaseView.swift */,
F935B15E1B2B8C7E003C3734 /* PKHUDWideBaseView.swift */,
F935B1601B2B8C8E003C3734 /* PKHUDTextView.swift */,
F935B1621B2B8CE2003C3734 /* PKHUDImageView.swift */,
F935B1641B2B8D0A003C3734 /* PKHUDProgressVIew.swift */,
F935B1661B2B8D8C003C3734 /* PKHUDSystemActivityIndicatorView.swift */,
F935B1681B2B8E10003C3734 /* PKHUDTitleView.swift */,
F935B16A1B2B8EA6003C3734 /* PKHUDSubtitleView.swift */,
F935B16C1B2B8F8B003C3734 /* PKHUDStatusVIew.swift */,
F935B16C1B2B8F8B003C3734 /* PKHUDStatusView.swift */,
F935B1661B2B8D8C003C3734 /* PKHUDSystemActivityIndicatorView.swift */,
F908BEBF1BB849290015E5A8 /* PKHUDSuccessView.swift */,
F908BEC41BB852C60015E5A8 /* PKHUDErrorAnimation.swift */,
F908BEC71BB85EA70015E5A8 /* PKHUDProgressView.swift */,
);
name = "Content Views";
sourceTree = "<group>";
Expand Down Expand Up @@ -325,14 +342,17 @@
F935B1631B2B8CE2003C3734 /* PKHUDImageView.swift in Sources */,
F935B1611B2B8C8E003C3734 /* PKHUDTextView.swift in Sources */,
F996325319514FEF001F73CA /* WindowRootViewController.swift in Sources */,
F935B16D1B2B8F8B003C3734 /* PKHUDStatusVIew.swift in Sources */,
F908BEC31BB84D0B0015E5A8 /* PKHUDAnimating.swift in Sources */,
F908BEC81BB85EA70015E5A8 /* PKHUDProgressView.swift in Sources */,
F935B16D1B2B8F8B003C3734 /* PKHUDStatusView.swift in Sources */,
F908BEC01BB849290015E5A8 /* PKHUDSuccessView.swift in Sources */,
F908BEC51BB852C60015E5A8 /* PKHUDErrorAnimation.swift in Sources */,
F935B16B1B2B8EA6003C3734 /* PKHUDSubtitleView.swift in Sources */,
F935B15D1B2B8C20003C3734 /* PKHUDSquareBaseView.swift in Sources */,
F996325219514FEF001F73CA /* Window.swift in Sources */,
F935B15F1B2B8C7E003C3734 /* PKHUDWideBaseView.swift in Sources */,
F996324D19514FEF001F73CA /* PKHUDAssets.swift in Sources */,
F935B1691B2B8E10003C3734 /* PKHUDTitleView.swift in Sources */,
F935B1651B2B8D0A003C3734 /* PKHUDProgressVIew.swift in Sources */,
F996324F19514FEF001F73CA /* PKHUD.swift in Sources */,
F935B1671B2B8D8C003C3734 /* PKHUDSystemActivityIndicatorView.swift in Sources */,
);
Expand Down
10 changes: 10 additions & 0 deletions PKHUD/PKHUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,23 @@ public class PKHUD: NSObject {
if dimsBackground {
window.showBackground(animated: true)
}

if contentView.conformsToProtocol(PKHUDAnimating) {
let animatingContentView = contentView as! PKHUDAnimating
animatingContentView.startAnimation()
}
}

public func hide(animated anim: Bool = true) {
window.hideFrameView(animated: anim)
if dimsBackground {
window.hideBackground(animated: true)
}

if contentView.conformsToProtocol(PKHUDAnimating) {
let animatingContentView = contentView as! PKHUDAnimating
animatingContentView.stopAnimation?()
}
}

private var hideTimer: NSTimer?
Expand Down
16 changes: 16 additions & 0 deletions PKHUD/PKHUDAnimating.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// PKHUDAnimatingContentView.swift
// PKHUD
//
// Created by Philip Kluz on 9/27/15.
// Copyright (c) 2015 NSExceptional. All rights reserved.
//

import UIKit

@objc protocol PKHUDAnimating {

func startAnimation()
optional func stopAnimation()
}

79 changes: 79 additions & 0 deletions PKHUD/PKHUDErrorAnimation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// PKHUDErrorAnimation.swift
// PKHUD
//
// Created by Philip Kluz on 9/27/15.
// Copyright (c) 2015 NSExceptional. All rights reserved.
//

import UIKit

/// PKHUDErrorAnimation provides an animated error (cross) view.
public class PKHUDErrorAnimation: PKHUDSquareBaseView, PKHUDAnimating {

var dashOneLayer = PKHUDErrorAnimation.generateDashLayer()
var dashTwoLayer = PKHUDErrorAnimation.generateDashLayer()

class func generateDashLayer() -> CAShapeLayer {
let dash = CAShapeLayer()
dash.frame = CGRectMake(0.0, 0.0, 88.0, 88.0)
dash.path = {
let path = UIBezierPath()
path.moveToPoint(CGPointMake(0.0, 44.0))
path.addLineToPoint(CGPointMake(88.0, 44.0))
return path.CGPath
}()
dash.lineCap = kCALineCapRound
dash.lineJoin = kCALineJoinRound
dash.fillColor = nil
dash.strokeColor = UIColor(red: 0.15, green: 0.15, blue: 0.15, alpha: 1.0).CGColor
dash.lineWidth = 6
dash.fillMode = kCAFillModeForwards;
return dash
}

public override init() {
super.init()
layer.addSublayer(dashOneLayer)
layer.addSublayer(dashTwoLayer)
dashOneLayer.position = layer.position
dashTwoLayer.position = layer.position
}

public required init?(coder aDecoder: NSCoder)
{
super.init(coder: aDecoder)
layer.addSublayer(dashOneLayer)
layer.addSublayer(dashTwoLayer)
dashOneLayer.position = layer.position
dashTwoLayer.position = layer.position
}

func springyRotationAnimation(angle: CGFloat) -> CASpringAnimation {
let animation = CASpringAnimation(keyPath:"transform.rotation.z")
animation.fromValue = 0.0
animation.toValue = angle * CGFloat(M_PI / 180.0)
animation.duration = 1.0
animation.damping = 1.5
animation.mass = 0.22
animation.initialVelocity = 0.5
animation.timingFunction = CAMediaTimingFunction(name:kCAMediaTimingFunctionEaseInEaseOut)
return animation
}

func startAnimation() {
let dashOneAnimation = springyRotationAnimation(-45.0)
let dashTwoAnimation = springyRotationAnimation(45.0)

dashOneLayer.transform = CATransform3DMakeRotation(-45 * CGFloat(M_PI/180), 0.0, 0.0, 1.0)
dashTwoLayer.transform = CATransform3DMakeRotation(45 * CGFloat(M_PI/180), 0.0, 0.0, 1.0)

dashOneLayer.addAnimation(dashOneAnimation, forKey: "dashOneAnimation")
dashTwoLayer.addAnimation(dashTwoAnimation, forKey: "dashTwoAnimation")
}

func stopAnimation() {
dashOneLayer.removeAnimationForKey("dashOneAnimation")
dashTwoLayer.removeAnimationForKey("dashTwoAnimation")
}
}
Loading

0 comments on commit 55f5efa

Please sign in to comment.