Skip to content

Updated to Swift 4. #1

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
39 changes: 36 additions & 3 deletions CustomActivityIndicatorViewTest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,12 @@
8BA9A7B21A7246B100E98FAF /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0610;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = syuryev;
TargetAttributes = {
8BA9A7B91A7246B100E98FAF = {
CreatedOnToolsVersion = 6.1.1;
DevelopmentTeam = 3JXFDJC3ZJ;
};
8BA9A7CE1A7246B100E98FAF = {
CreatedOnToolsVersion = 6.1.1;
Expand Down Expand Up @@ -275,20 +276,30 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
Expand All @@ -301,7 +312,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand All @@ -318,29 +329,39 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -350,19 +371,27 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 3JXFDJC3ZJ;
INFOPLIST_FILE = CustomActivityIndicatorViewTest/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.syuryev.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
};
name = Debug;
};
8BA9A7DB1A7246B100E98FAF /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 3JXFDJC3ZJ;
INFOPLIST_FILE = CustomActivityIndicatorViewTest/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.syuryev.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -380,6 +409,7 @@
);
INFOPLIST_FILE = CustomActivityIndicatorViewTestTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.syuryev.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CustomActivityIndicatorViewTest.app/CustomActivityIndicatorViewTest";
};
Expand All @@ -395,6 +425,7 @@
);
INFOPLIST_FILE = CustomActivityIndicatorViewTestTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.syuryev.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CustomActivityIndicatorViewTest.app/CustomActivityIndicatorViewTest";
};
Expand All @@ -419,6 +450,7 @@
8BA9A7DB1A7246B100E98FAF /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
8BA9A7DC1A7246B100E98FAF /* Build configuration list for PBXNativeTarget "CustomActivityIndicatorViewTestTests" */ = {
isa = XCConfigurationList;
Expand All @@ -427,6 +459,7 @@
8BA9A7DE1A7246B100E98FAF /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
64 changes: 32 additions & 32 deletions CustomActivityIndicatorViewTest/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,37 @@ import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


var window: UIWindow?
private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
return true
}
internal func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}

155 changes: 78 additions & 77 deletions CustomActivityIndicatorViewTest/CustomActivityIndicatorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,91 +10,92 @@ import UIKit
import QuartzCore

class CustomActivityIndicatorView: UIView {

// MARK - Variables

lazy private var animationLayer : CALayer = {
return CALayer()
}()

var isAnimating : Bool = false
var hidesWhenStopped : Bool = true

// MARK - Init

init(image : UIImage) {
let frame : CGRect = CGRect(x: 0.0, y: 0.0, width: image.size.width, height: image.size.height)

// MARK - Variables
super.init(frame: frame)

lazy private var animationLayer : CALayer = {
return CALayer()
}()
animationLayer.frame = frame
animationLayer.contents = image.cgImage
animationLayer.masksToBounds = true

var isAnimating : Bool = false
var hidesWhenStopped : Bool = true
self.layer.addSublayer(animationLayer)

// MARK - Init
addRotation(forLayer: animationLayer)
pause(layer: animationLayer)
self.isHidden = true
}

required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK - Func

func addRotation(forLayer layer : CALayer) {
let rotation : CABasicAnimation = CABasicAnimation(keyPath:"transform.rotation.z")

init(image : UIImage) {
let frame : CGRect = CGRectMake(0.0, 0.0, image.size.width, image.size.height)

super.init(frame: frame)

animationLayer.frame = frame
animationLayer.contents = image.CGImage
animationLayer.masksToBounds = true

self.layer.addSublayer(animationLayer)

addRotation(forLayer: animationLayer)
pause(layer: animationLayer)
self.hidden = true
}

required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
rotation.duration = 1.0
rotation.isRemovedOnCompletion = false
rotation.repeatCount = HUGE
rotation.fillMode = kCAFillModeForwards
rotation.fromValue = NSNumber(value: 0.0)
rotation.toValue = NSNumber(value: 3.14 * 2.0)

// MARK - Func
layer.add(rotation, forKey: "rotate")
}

func pause(layer : CALayer) {
let pausedTime = layer.convertTime(CACurrentMediaTime(), from: nil)

func addRotation(forLayer layer : CALayer) {
let rotation : CABasicAnimation = CABasicAnimation(keyPath:"transform.rotation.z")

rotation.duration = 1.0
rotation.removedOnCompletion = false
rotation.repeatCount = HUGE
rotation.fillMode = kCAFillModeForwards
rotation.fromValue = NSNumber(float: 0.0)
rotation.toValue = NSNumber(float: 3.14 * 2.0)

layer.addAnimation(rotation, forKey: "rotate")
}

func pause(#layer : CALayer) {
let pausedTime = layer.convertTime(CACurrentMediaTime(), fromLayer: nil)

layer.speed = 0.0
layer.timeOffset = pausedTime

isAnimating = false
}

func resume(#layer : CALayer) {
let pausedTime : CFTimeInterval = layer.timeOffset

layer.speed = 1.0
layer.timeOffset = 0.0
layer.beginTime = 0.0

let timeSincePause = layer.convertTime(CACurrentMediaTime(), fromLayer: nil) - pausedTime
layer.beginTime = timeSincePause

isAnimating = true
layer.speed = 0.0
layer.timeOffset = pausedTime

isAnimating = false
}

func resume(layer : CALayer) {
let pausedTime : CFTimeInterval = layer.timeOffset

layer.speed = 1.0
layer.timeOffset = 0.0
layer.beginTime = 0.0

let timeSincePause = layer.convertTime(CACurrentMediaTime(), from: nil) - pausedTime
layer.beginTime = timeSincePause

isAnimating = true
}

func startAnimating () {

if isAnimating {
return
}

func startAnimating () {

if isAnimating {
return
}

if hidesWhenStopped {
self.hidden = false
}
resume(layer: animationLayer)

if hidesWhenStopped {
self.isHidden = false
}

func stopAnimating () {
if hidesWhenStopped {
self.hidden = true
}
pause(layer: animationLayer)
resume(layer: animationLayer)
}

func stopAnimating () {
if hidesWhenStopped {
self.isHidden = true
}
pause(layer: animationLayer)
}
}

Loading