Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[f] Add custom transition animation features: flip, fade.. #144

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions Demo/DemoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ class DemoViewController: UIViewController {

@IBAction func showCustomProgressHUD(_ sender: AnyObject) {
HUD.flash(.rotatingImage(UIImage(named: "progress")), delay: 2.0)

}

@IBAction func showCustomAnimationTypeHUD(_ sender: Any) {
HUD.flash(.customTransition(image: UIImage(named: "progress"), animationType: .flip), delay: 2.0)
}

@IBAction func showAnimatedStatusProgressHUD(_ sender: AnyObject) {
HUD.flash(.labeledProgress(title: "Title", subtitle: "Subtitle"), delay: 2.0)
}
Expand Down
85 changes: 52 additions & 33 deletions Demo/Storyboard.storyboard

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions PKHUD.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
12CE19FD1E2578680062D873 /* PKHUD.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F996321E19514FD8001F73CA /* PKHUD.framework */; };
3097AF3A1C4843AE007DD42B /* PKHUDRotatingImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3097AF391C4843AE007DD42B /* PKHUDRotatingImageView.swift */; };
640011571C5B6C080013F32B /* HUD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 640011551C5B6C080013F32B /* HUD.swift */; };
A242E8841E695A02004BC326 /* PKHUDCustomTransition.swift in Sources */ = {isa = PBXBuildFile; fileRef = A242E8831E695A02004BC326 /* PKHUDCustomTransition.swift */; };
F908BEC01BB849290015E5A8 /* PKHUDSuccessView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F908BEBF1BB849290015E5A8 /* PKHUDSuccessView.swift */; };
F908BEC31BB84D0B0015E5A8 /* PKHUDAnimating.swift in Sources */ = {isa = PBXBuildFile; fileRef = F908BEC21BB84D0B0015E5A8 /* PKHUDAnimating.swift */; };
F908BEC51BB852C60015E5A8 /* PKHUDErrorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F908BEC41BB852C60015E5A8 /* PKHUDErrorView.swift */; };
Expand Down Expand Up @@ -88,6 +89,7 @@
12CE19F51E25784D0062D873 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3097AF391C4843AE007DD42B /* PKHUDRotatingImageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDRotatingImageView.swift; sourceTree = "<group>"; };
640011551C5B6C080013F32B /* HUD.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HUD.swift; sourceTree = "<group>"; };
A242E8831E695A02004BC326 /* PKHUDCustomTransition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDCustomTransition.swift; sourceTree = "<group>"; };
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 /* PKHUDErrorView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDErrorView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -171,6 +173,7 @@
F908BEC71BB85EA70015E5A8 /* PKHUDProgressView.swift */,
12010C891C3D0E8D005DC6FC /* PKHUDAnimation.swift */,
3097AF391C4843AE007DD42B /* PKHUDRotatingImageView.swift */,
A242E8831E695A02004BC326 /* PKHUDCustomTransition.swift */,
);
name = "Content Views";
sourceTree = "<group>";
Expand Down Expand Up @@ -448,6 +451,7 @@
F935B15F1B2B8C7E003C3734 /* PKHUDWideBaseView.swift in Sources */,
F996324D19514FEF001F73CA /* PKHUDAssets.swift in Sources */,
F996324F19514FEF001F73CA /* PKHUD.swift in Sources */,
A242E8841E695A02004BC326 /* PKHUDCustomTransition.swift in Sources */,
F935B1671B2B8D8C003C3734 /* PKHUDSystemActivityIndicatorView.swift in Sources */,
12010C8A1C3D0E8D005DC6FC /* PKHUDAnimation.swift in Sources */,
);
Expand Down Expand Up @@ -695,6 +699,7 @@
12CE19F91E25784D0062D873 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
F99631F719514FAC001F73CA /* Build configuration list for PBXProject "PKHUD" */ = {
isa = XCConfigurationList;
Expand Down
10 changes: 10 additions & 0 deletions PKHUD/HUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum HUDContentType {
case progress
case image(UIImage?)
case rotatingImage(UIImage?)
case customTransition(image: UIImage?, animationType: AnimationType )

case labeledSuccess(title: String?, subtitle: String?)
case labeledError(title: String?, subtitle: String?)
Expand All @@ -26,6 +27,13 @@ public enum HUDContentType {
case systemActivity
}


public enum AnimationType {
case flip
case fade
case rotate
}

public final class HUD {

// MARK: Properties
Expand Down Expand Up @@ -83,6 +91,8 @@ public final class HUD {
return PKHUDSquareBaseView(image: image)
case let .rotatingImage(image):
return PKHUDRotatingImageView(image: image)
case let .customTransition(image: image, animationType: animationType):
return PKHUDCustomTransition(image:image, animationType: animationType)

case let .labeledSuccess(title, subtitle):
return PKHUDSuccessView(title: title, subtitle: subtitle)
Expand Down
24 changes: 24 additions & 0 deletions PKHUD/PKHUDAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,28 @@ public final class PKHUDAnimation {
animation.repeatCount = Float(INT_MAX)
return animation
}()

static let customAnimation: CAAnimation = {
let playing = true
let flip = CABasicAnimation(keyPath: "transform")
var t = CATransform3DIdentity
var z = CATransform3DIdentity
t.m34 = 1/1000.0
t = CATransform3DRotate(t, CGFloat(M_PI) * (playing ? 0.5 : 1.5), 0, 1, 0)
flip.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
flip.fromValue = NSValue(caTransform3D: z)
flip.toValue = NSValue(caTransform3D: t)
flip.repeatCount = Float(INT_MAX)
flip.duration = 0.15
return flip
}()

static let flipAnimation: CAAnimation = {
let flip = CABasicAnimation(keyPath: "transform.rotation.y")
flip.fromValue = 0
flip.toValue = Double(1) * 2 * M_PI
flip.duration = CFTimeInterval(1)
flip.repeatCount = Float(INT_MAX)
return flip
}()
}
26 changes: 26 additions & 0 deletions PKHUD/PKHUDCustomTransition.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// PKHUDCustomTransition.swift
// PKHUD
//
// Created by JohnP on 3/3/17.
// Copyright © 2017 NSExceptional. All rights reserved.
//

import Foundation
import QuartzCore

/// PKHUDCustomTransition provides a content view that custom trainsiton the supplied image automatically.
open class PKHUDCustomTransition: PKHUDSquareBaseView, PKHUDAnimating {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have added 3 animation and then you manage only the .flip. Why?

public func startAnimation() {
switch animationType {
case .flip:
imageView.layer.add(PKHUDAnimation.flipAnimation, forKey: "progressAnimation")
default:
imageView.layer.add(PKHUDAnimation.continuousRotation, forKey: "progressAnimation")
}
}

public func stopAnimation() {
}
}
6 changes: 4 additions & 2 deletions PKHUD/PKHUDSquareBaseView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import UIKit

/// PKHUDSquareBaseView provides a square view, which you can subclass and add additional views to.
open class PKHUDSquareBaseView: UIView {
var animationType: AnimationType = .flip

static let defaultSquareBaseViewFrame = CGRect(origin: CGPoint.zero, size: CGSize(width: 156.0, height: 156.0))

Expand All @@ -22,12 +23,13 @@ open class PKHUDSquareBaseView: UIView {
super.init(coder: aDecoder)
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the params at the end

public init(image: UIImage? = nil, title: String? = nil, subtitle: String? = nil) {
public init(image: UIImage? = nil, animationType: AnimationType = .flip, title: String? = nil, subtitle: String? = nil) {
super.init(frame: PKHUDSquareBaseView.defaultSquareBaseViewFrame)
self.imageView.image = image
titleLabel.text = title
subtitleLabel.text = subtitle

self.animationType = animationType

addSubview(imageView)
addSubview(titleLabel)
addSubview(subtitleLabel)
Expand Down