diff --git a/Demo/DemoViewController.swift b/Demo/DemoViewController.swift index 0651e42..80325b9 100644 --- a/Demo/DemoViewController.swift +++ b/Demo/DemoViewController.swift @@ -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) } @@ -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; } diff --git a/Demo/Launch Screen.storyboard b/Demo/Launch Screen.storyboard index 63ab589..51241ed 100644 --- a/Demo/Launch Screen.storyboard +++ b/Demo/Launch Screen.storyboard @@ -1,7 +1,7 @@ - + - + diff --git a/Demo/Storyboard.storyboard b/Demo/Storyboard.storyboard index 56adde1..fff4653 100644 --- a/Demo/Storyboard.storyboard +++ b/Demo/Storyboard.storyboard @@ -1,7 +1,7 @@ - + - + @@ -21,98 +21,71 @@ - - + + - - - - - - - @@ -122,20 +95,20 @@ - + + + - - - + diff --git a/PKHUD.podspec b/PKHUD.podspec index f0779ee..7a60174 100644 --- a/PKHUD.podspec +++ b/PKHUD.podspec @@ -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' diff --git a/PKHUD.xcodeproj/project.pbxproj b/PKHUD.xcodeproj/project.pbxproj index 801831a..62001d0 100644 --- a/PKHUD.xcodeproj/project.pbxproj +++ b/PKHUD.xcodeproj/project.pbxproj @@ -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, ); }; }; @@ -64,17 +67,20 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + F908BEBF1BB849290015E5A8 /* PKHUDSuccessView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDSuccessView.swift; sourceTree = ""; }; + F908BEC21BB84D0B0015E5A8 /* PKHUDAnimating.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDAnimating.swift; sourceTree = ""; }; + F908BEC41BB852C60015E5A8 /* PKHUDErrorAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDErrorAnimation.swift; sourceTree = ""; }; + F908BEC71BB85EA70015E5A8 /* PKHUDProgressView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDProgressView.swift; sourceTree = ""; }; F935B1571B2B8088003C3734 /* Storyboard.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Storyboard.storyboard; sourceTree = ""; }; F935B1591B2B865A003C3734 /* Launch Screen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = ""; }; F935B15C1B2B8C20003C3734 /* PKHUDSquareBaseView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDSquareBaseView.swift; sourceTree = ""; }; F935B15E1B2B8C7E003C3734 /* PKHUDWideBaseView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDWideBaseView.swift; sourceTree = ""; }; F935B1601B2B8C8E003C3734 /* PKHUDTextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDTextView.swift; sourceTree = ""; }; F935B1621B2B8CE2003C3734 /* PKHUDImageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDImageView.swift; sourceTree = ""; }; - F935B1641B2B8D0A003C3734 /* PKHUDProgressVIew.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDProgressVIew.swift; sourceTree = ""; }; F935B1661B2B8D8C003C3734 /* PKHUDSystemActivityIndicatorView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDSystemActivityIndicatorView.swift; sourceTree = ""; }; F935B1681B2B8E10003C3734 /* PKHUDTitleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDTitleView.swift; sourceTree = ""; }; F935B16A1B2B8EA6003C3734 /* PKHUDSubtitleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDSubtitleView.swift; sourceTree = ""; }; - F935B16C1B2B8F8B003C3734 /* PKHUDStatusVIew.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDStatusVIew.swift; sourceTree = ""; }; + F935B16C1B2B8F8B003C3734 /* PKHUDStatusView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDStatusView.swift; sourceTree = ""; }; 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 = ""; }; F996320119514FAC001F73CA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -110,18 +116,29 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + F908BEC11BB84D010015E5A8 /* Protocol */ = { + isa = PBXGroup; + children = ( + F908BEC21BB84D0B0015E5A8 /* PKHUDAnimating.swift */, + ); + name = Protocol; + sourceTree = ""; + }; 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 = ""; @@ -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 */, ); diff --git a/PKHUD/PKHUD.swift b/PKHUD/PKHUD.swift index 1a8b32a..ebabe1e 100644 --- a/PKHUD/PKHUD.swift +++ b/PKHUD/PKHUD.swift @@ -51,6 +51,11 @@ 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) { @@ -58,6 +63,11 @@ public class PKHUD: NSObject { if dimsBackground { window.hideBackground(animated: true) } + + if contentView.conformsToProtocol(PKHUDAnimating) { + let animatingContentView = contentView as! PKHUDAnimating + animatingContentView.stopAnimation?() + } } private var hideTimer: NSTimer? diff --git a/PKHUD/PKHUDAnimating.swift b/PKHUD/PKHUDAnimating.swift new file mode 100644 index 0000000..ba0021b --- /dev/null +++ b/PKHUD/PKHUDAnimating.swift @@ -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() +} + diff --git a/PKHUD/PKHUDErrorAnimation.swift b/PKHUD/PKHUDErrorAnimation.swift new file mode 100644 index 0000000..f9312fe --- /dev/null +++ b/PKHUD/PKHUDErrorAnimation.swift @@ -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") + } +} diff --git a/PKHUD/PKHUDProgressVIew.swift b/PKHUD/PKHUDProgressVIew.swift deleted file mode 100644 index 55eed22..0000000 --- a/PKHUD/PKHUDProgressVIew.swift +++ /dev/null @@ -1,70 +0,0 @@ -// -// PKHUDProgressVIew.swift -// PKHUD -// -// Created by Philip Kluz on 6/12/15. -// Copyright (c) 2015 NSExceptional. All rights reserved. -// - -import UIKit -import QuartzCore - -/// PKHUDProgressView provides a square (indeterminate) progress view. -public final class PKHUDProgressView: PKHUDImageView { - - public init() { - super.init(image: PKHUDAssets.progressImage) - } - - public required init?(coder aDecoder: NSCoder) { - super.init(coder: aDecoder) - } - - override func commonInit(image image: UIImage?) { - super.commonInit(image: image) - - let progressImage = PKHUDAssets.progressImage - imageView.image = progressImage - - let keyframeAnimation : CAKeyframeAnimation = ({ - let animation = CAKeyframeAnimation(keyPath: "transform.rotation.z") - animation.values = [ - NSNumber(float: 0.0), - NSNumber(float: 1.0 * Float(M_PI) / 6.0), - NSNumber(float: 2.0 * Float(M_PI) / 6.0), - NSNumber(float: 3.0 * Float(M_PI) / 6.0), - NSNumber(float: 4.0 * Float(M_PI) / 6.0), - NSNumber(float: 5.0 * Float(M_PI) / 6.0), - NSNumber(float: 6.0 * Float(M_PI) / 6.0), - NSNumber(float: 7.0 * Float(M_PI) / 6.0), - NSNumber(float: 8.0 * Float(M_PI) / 6.0), - NSNumber(float: 9.0 * Float(M_PI) / 6.0), - NSNumber(float: 10.0 * Float(M_PI) / 6.0), - NSNumber(float: 11.0 * Float(M_PI) / 6.0), - NSNumber(float: 2.0 * Float(M_PI)) - ] - animation.keyTimes = [ - NSNumber(float: 0.0), - NSNumber(float: 1.0 / 12.0), - NSNumber(float: 2.0 / 12.0), - NSNumber(float: 3.0 / 12.0), - NSNumber(float: 4.0 / 12.0), - NSNumber(float: 5.0 / 12.0), - NSNumber(float: 0.5), - NSNumber(float: 7.0 / 12.0), - NSNumber(float: 8.0 / 12.0), - NSNumber(float: 9.0 / 12.0), - NSNumber(float: 10.0 / 12.0), - NSNumber(float: 11.0 / 12.0), - NSNumber(float: 1.0) - ] - animation.duration = 1.2 - animation.calculationMode = "discrete" - animation.repeatCount = Float(INT_MAX) - return animation - })() - - imageView.layer.addAnimation(keyframeAnimation, forKey: "transform.rotation.z") - imageView.alpha = 0.9 - } -} diff --git a/PKHUD/PKHUDProgressView.swift b/PKHUD/PKHUDProgressView.swift new file mode 100644 index 0000000..bf01194 --- /dev/null +++ b/PKHUD/PKHUDProgressView.swift @@ -0,0 +1,75 @@ +// +// PKHUDProgressVIew.swift +// PKHUD +// +// Created by Philip Kluz on 6/12/15. +// Copyright (c) 2015 NSExceptional. All rights reserved. +// + +import UIKit +import QuartzCore + +/// PKHUDProgressView provides an indeterminate progress view. +public class PKHUDProgressView: PKHUDImageView, PKHUDAnimating { + + public init() { + super.init(image: PKHUDAssets.progressImage) + } + + public required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + } + + override func commonInit(image image: UIImage?) { + super.commonInit(image: image) + + let progressImage = PKHUDAssets.progressImage + imageView.image = progressImage + imageView.alpha = 0.9 + } + + let progressAnimation: CAKeyframeAnimation = { + let animation = CAKeyframeAnimation(keyPath: "transform.rotation.z") + animation.values = [ + NSNumber(float: 0.0), + NSNumber(float: 1.0 * Float(M_PI) / 6.0), + NSNumber(float: 2.0 * Float(M_PI) / 6.0), + NSNumber(float: 3.0 * Float(M_PI) / 6.0), + NSNumber(float: 4.0 * Float(M_PI) / 6.0), + NSNumber(float: 5.0 * Float(M_PI) / 6.0), + NSNumber(float: 6.0 * Float(M_PI) / 6.0), + NSNumber(float: 7.0 * Float(M_PI) / 6.0), + NSNumber(float: 8.0 * Float(M_PI) / 6.0), + NSNumber(float: 9.0 * Float(M_PI) / 6.0), + NSNumber(float: 10.0 * Float(M_PI) / 6.0), + NSNumber(float: 11.0 * Float(M_PI) / 6.0), + NSNumber(float: 2.0 * Float(M_PI)) + ] + animation.keyTimes = [ + NSNumber(float: 0.0), + NSNumber(float: 1.0 / 12.0), + NSNumber(float: 2.0 / 12.0), + NSNumber(float: 3.0 / 12.0), + NSNumber(float: 4.0 / 12.0), + NSNumber(float: 5.0 / 12.0), + NSNumber(float: 0.5), + NSNumber(float: 7.0 / 12.0), + NSNumber(float: 8.0 / 12.0), + NSNumber(float: 9.0 / 12.0), + NSNumber(float: 10.0 / 12.0), + NSNumber(float: 11.0 / 12.0), + NSNumber(float: 1.0) + ] + animation.duration = 1.2 + animation.calculationMode = "discrete" + animation.repeatCount = Float(INT_MAX) + return animation + }() + + func startAnimation() { + imageView.layer.addAnimation(progressAnimation, forKey: "progressAnimation") + } + + func stopAnimation() { + } +} diff --git a/PKHUD/PKHUDStatusVIew.swift b/PKHUD/PKHUDStatusView.swift similarity index 100% rename from PKHUD/PKHUDStatusVIew.swift rename to PKHUD/PKHUDStatusView.swift diff --git a/PKHUD/PKHUDSuccessView.swift b/PKHUD/PKHUDSuccessView.swift new file mode 100644 index 0000000..f72199f --- /dev/null +++ b/PKHUD/PKHUDSuccessView.swift @@ -0,0 +1,57 @@ +// +// PKHUDCheckmarkView.swift +// PKHUD +// +// Created by Philip Kluz on 9/27/15. +// Copyright (c) 2015 NSExceptional. All rights reserved. +// + +import UIKit + +/// PKHUDCheckmarkView provides an animated success (checkmark) view. +public class PKHUDSuccessView: PKHUDSquareBaseView, PKHUDAnimating { + + var checkmarkShapeLayer: CAShapeLayer = { + let checkmarkPath = UIBezierPath() + checkmarkPath.moveToPoint(CGPointMake(4.0, 27.0)) + checkmarkPath.addLineToPoint(CGPointMake(34.0, 56.0)) + checkmarkPath.addLineToPoint(CGPointMake(88.0, 0.0)) + + let layer = CAShapeLayer() + layer.frame = CGRectMake(3.0, 3.0, 88.0, 56.0) + layer.path = checkmarkPath.CGPath + layer.fillMode = kCAFillModeForwards + layer.lineCap = kCALineCapRound + layer.lineJoin = kCALineJoinRound + layer.fillColor = nil + layer.strokeColor = UIColor(red: 0.15, green: 0.15, blue: 0.15, alpha: 1.0).CGColor + layer.lineWidth = 6.0 + + return layer + }() + + public required override init() { + super.init() + layer.addSublayer(checkmarkShapeLayer) + checkmarkShapeLayer.position = layer.position + } + + public required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + layer.addSublayer(checkmarkShapeLayer) + checkmarkShapeLayer.position = layer.position + } + + public func startAnimation() { + let checkmarkStrokeAnimation = CAKeyframeAnimation(keyPath:"strokeEnd") + checkmarkStrokeAnimation.values = [0, 1] + checkmarkStrokeAnimation.keyTimes = [0, 1] + checkmarkStrokeAnimation.duration = 0.35 + + checkmarkShapeLayer.addAnimation(checkmarkStrokeAnimation, forKey:"checkmarkStrokeAnim") + } + + public func stopAnimation() { + checkmarkShapeLayer.removeAnimationForKey("checkmarkStrokeAnimation") + } +} diff --git a/PKHUD/PKHUDSystemActivityIndicatorView.swift b/PKHUD/PKHUDSystemActivityIndicatorView.swift index 5cb7ecf..8716205 100644 --- a/PKHUD/PKHUDSystemActivityIndicatorView.swift +++ b/PKHUD/PKHUDSystemActivityIndicatorView.swift @@ -9,33 +9,42 @@ import UIKit /// PKHUDSystemActivityIndicatorView provides the system UIActivityIndicatorView as an alternative. -public final class PKHUDSystemActivityIndicatorView: PKHUDSquareBaseView { +public final class PKHUDSystemActivityIndicatorView: PKHUDSquareBaseView, PKHUDAnimating { public override init() { super.init(frame: PKHUDSquareBaseView.defaultSquareBaseViewFrame) - self.commonInit() + commonInit() } public override init(frame: CGRect) { super.init(frame: frame) - self.commonInit() + commonInit() } public required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) - self.commonInit() + commonInit() } func commonInit () { - self.backgroundColor = UIColor.clearColor() - self.alpha = 0.8 + backgroundColor = UIColor.clearColor() + alpha = 0.8 + self.addSubview(activityIndicatorView) + } + + public override func layoutSubviews() { + super.layoutSubviews() + activityIndicatorView.center = self.center + } + + let activityIndicatorView: UIActivityIndicatorView = { let activity = UIActivityIndicatorView(activityIndicatorStyle: .WhiteLarge) activity.color = UIColor.blackColor() - activity.startAnimating() - - self.addSubview(activity) - - activity.center = self.center + return activity + }() + + func startAnimation() { + activityIndicatorView.startAnimating() } }