Skip to content
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
Binary file added .DS_Store
Binary file not shown.
Binary file added Example/.DS_Store
Binary file not shown.
29 changes: 2 additions & 27 deletions Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,9 @@ import UIKit
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)

let rootViewController: DemoViewController = DemoViewController()
self.window!.rootViewController = rootViewController

self.window!.makeKeyAndVisible()


private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
return true
}

func applicationWillResignActive(application: UIApplication) {
}

func applicationDidEnterBackground(application: UIApplication) {
}

func applicationWillEnterForeground(application: UIApplication) {
}

func applicationDidBecomeActive(application: UIApplication) {
}

func applicationWillTerminate(application: UIApplication) {
}


}

10 changes: 10 additions & 0 deletions Example/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down
10 changes: 5 additions & 5 deletions Example/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9059" systemVersion="15B42" 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="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -14,10 +15,9 @@
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down
28 changes: 28 additions & 0 deletions Example/Base.lproj/Storyboard.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="7DP-oA-xhV">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Demo View Controller-->
<scene sceneID="8oO-k9-jt3">
<objects>
<viewController id="7DP-oA-xhV" customClass="DemoViewController" customModule="Loader" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="zL5-cV-1oG"/>
<viewControllerLayoutGuide type="bottom" id="DkK-FI-Xft"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="uto-Fs-Sp2">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="idH-wm-oVg" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-186" y="133"/>
</scene>
</scenes>
</document>
16 changes: 10 additions & 6 deletions Example/DemoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,28 @@ class DemoViewController: UIViewController {

var loader: Loader!

// override var prefersStatusBarHidden: Bool {
// return true
// }

override func loadView() {
super.loadView()

self.view.backgroundColor = UIColor(red: 175.0 / 255.0, green: 85.0 / 255.0, blue: 255.0 / 255.0, alpha: 1.0)

self.loader = Loader(frame: CGRectMake(0.0, 0.0, 80.0, 40.0))
self.loader = Loader(frame: CGRect(x: 0.0, y: 0.0, width: 80.0, height: 40.0))
loader.center = self.view.center

self.view.addSubview(loader)
}

override func viewDidAppear(animated: Bool) {
override func viewDidLoad() {
super.viewDidLoad()
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

self.loader.startAnimating()
}

override func prefersStatusBarHidden() -> Bool {
return true
}
}
2 changes: 2 additions & 0 deletions Example/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Storyboard</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
Expand Down
24 changes: 23 additions & 1 deletion Loader.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
88FA7E341D961802006C3CC8 /* Storyboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 88FA7E321D961802006C3CC8 /* Storyboard.storyboard */; };
BE57DF201C149DF40071595C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE57DF181C149DF40071595C /* AppDelegate.swift */; };
BE57DF211C149DF40071595C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BE57DF191C149DF40071595C /* Assets.xcassets */; };
BE57DF221C149DF40071595C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BE57DF1A1C149DF40071595C /* LaunchScreen.storyboard */; };
Expand All @@ -16,6 +17,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
88FA7E331D961802006C3CC8 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Example/Base.lproj/Storyboard.storyboard; sourceTree = SOURCE_ROOT; };
BE3156741C149D0F00BA4E59 /* Loader.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Loader.app; sourceTree = BUILT_PRODUCTS_DIR; };
BE57DF181C149DF40071595C /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = Example/AppDelegate.swift; sourceTree = SOURCE_ROOT; };
BE57DF191C149DF40071595C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Example/Assets.xcassets; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -62,6 +64,7 @@
BE57DF1A1C149DF40071595C /* LaunchScreen.storyboard */,
BE57DF1E1C149DF40071595C /* Info.plist */,
BEE0F2851C149EDC00AFA2DE /* DemoViewController.swift */,
88FA7E321D961802006C3CC8 /* Storyboard.storyboard */,
);
path = Loader;
sourceTree = "<group>";
Expand Down Expand Up @@ -102,11 +105,12 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0710;
LastUpgradeCheck = 0710;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = Ekhoo;
TargetAttributes = {
BE3156731C149D0F00BA4E59 = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -135,6 +139,7 @@
files = (
BE57DF211C149DF40071595C /* Assets.xcassets in Resources */,
BE57DF221C149DF40071595C /* LaunchScreen.storyboard in Resources */,
88FA7E341D961802006C3CC8 /* Storyboard.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -155,6 +160,14 @@
/* End PBXSourcesBuildPhase section */

/* Begin PBXVariantGroup section */
88FA7E321D961802006C3CC8 /* Storyboard.storyboard */ = {
isa = PBXVariantGroup;
children = (
88FA7E331D961802006C3CC8 /* Base */,
);
name = Storyboard.storyboard;
sourceTree = "<group>";
};
BE57DF1A1C149DF40071595C /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup;
children = (
Expand All @@ -179,8 +192,10 @@
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_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -223,8 +238,10 @@
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_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -243,6 +260,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.1;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -252,12 +270,14 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = "$(SRCROOT)/Example/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = Ekhoo.Loader;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -266,11 +286,13 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = "$(SRCROOT)/Example/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = Ekhoo.Loader;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
Binary file added Source/.DS_Store
Binary file not shown.
32 changes: 16 additions & 16 deletions Source/Loader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Loader: UIView {

private var switchView: UIView?
private var switchAnimationSide: Bool = false
private var animationTimer: NSTimer?
private var animationTimer: Timer?

var loaderColor: UIColor {
didSet {
Expand All @@ -30,17 +30,17 @@ public class Loader: UIView {
}

override init(frame: CGRect) {
self.loaderColor = UIColor.whiteColor()
self.switchColor = UIColor(red: 175.0 / 255.0, green: 85.0 / 255.0, blue: 255.0 / 255.0, alpha: 1.0)
self.loaderColor = UIColor.white
self.switchColor = UIColor(red: 255.0 / 255.0, green: 195.0 / 255.0, blue: 117.0 / 255.0, alpha: 1.0)

super.init(frame: frame)

self.switchView = UIView(frame: CGRectMake(kInset, kInset, frame.size.height - 2 * kInset, frame.size.height - 2 * kInset))
self.switchView = UIView(frame: CGRect(x: kInset, y: kInset, width: frame.size.height - 2 * kInset, height: frame.size.height - 2 * kInset))
self.switchView!.backgroundColor = self.switchColor
self.switchView!.layer.cornerRadius = round(self.switchView!.frame.size.width / 2)
self.switchView!.layer.masksToBounds = true

self.backgroundColor = UIColor.clearColor()
self.backgroundColor = UIColor.clear

self.addSubview(self.switchView!)
}
Expand All @@ -54,24 +54,24 @@ public class Loader: UIView {
return;
}

UIView.animateWithDuration(0.3, delay: 0.0, options: UIViewAnimationOptions.AllowAnimatedContent, animations: { () -> Void in
UIView.animate(withDuration: 0.3, delay: 0.0, options: UIViewAnimationOptions.allowAnimatedContent, animations: { () -> Void in
let frame: CGRect = self.bounds

if self.switchView!.frame.origin.x > kInset {
self.switchView!.frame = CGRectMake(kInset, self.switchView!.frame.origin.y, frame.width - 2 * kInset, self.switchView!.frame.height)
self.switchView!.frame = CGRect(x: kInset, y: self.switchView!.frame.origin.y, width: frame.width - 2 * kInset, height: self.switchView!.frame.height)
} else {
self.switchView!.frame = CGRectMake(self.switchView!.frame.origin.x, self.switchView!.frame.origin.y, frame.width - 2 * kInset, self.switchView!.frame.height)
self.switchView!.frame = CGRect(x: self.switchView!.frame.origin.x, y: self.switchView!.frame.origin.y, width: frame.width - 2 * kInset, height: self.switchView!.frame.height)
}

self.switchView!.setNeedsDisplay()
}) { (finished) -> Void in
UIView.animateWithDuration(0.30, animations: { () -> Void in
UIView.animate(withDuration: 0.30, animations: { () -> Void in
let frame: CGRect = self.bounds

if self.switchAnimationSide {
self.switchView!.frame = CGRectMake(kInset, self.switchView!.frame.origin.y, self.switchView!.frame.size.height, self.switchView!.frame.height)
self.switchView!.frame = CGRect(x: kInset, y: self.switchView!.frame.origin.y, width: self.switchView!.frame.size.height, height: self.switchView!.frame.height)
} else {
self.switchView!.frame = CGRectMake(frame.size.width - self.switchView!.frame.height - kInset, self.switchView!.frame.origin.y, self.switchView!.frame.size.height, self.switchView!.frame.height)
self.switchView!.frame = CGRect(x: frame.size.width - self.switchView!.frame.height - kInset, y: self.switchView!.frame.origin.y, width: self.switchView!.frame.size.height, height: self.switchView!.frame.height)
}

self.switchAnimationSide = !self.switchAnimationSide
Expand All @@ -82,15 +82,15 @@ public class Loader: UIView {
}

@objc private func animateLoader() {
UIView.animateWithDuration(0.4) { () -> Void in
self.transform = CGAffineTransformRotate(self.transform, CGFloat(M_PI_2));
UIView.animate(withDuration: 0.4) { () -> Void in
self.transform = self.transform.rotated(by: CGFloat(M_PI_2));
}

animateSwitch()
}

public func startAnimating() {
self.animationTimer = NSTimer.scheduledTimerWithTimeInterval(0.4, target: self, selector: "animateLoader", userInfo: nil, repeats: true)
self.animationTimer = Timer.scheduledTimer(timeInterval: 0.4, target: self, selector: #selector(Loader.animateLoader), userInfo: nil, repeats: true)
}

public func stopAnimating() {
Expand All @@ -101,8 +101,8 @@ public class Loader: UIView {
}
}

override public func drawRect(rect: CGRect) {
let rectanglePath = UIBezierPath(roundedRect: CGRectMake(0.0, 0.0, rect.size.width, rect.size.height), cornerRadius: round(rect.size.width / 2.0))
override public func draw(_ rect: CGRect) {
let rectanglePath = UIBezierPath(roundedRect: CGRect(x: 0.0, y: 0.0, width: rect.size.width, height: rect.size.height), cornerRadius: round(rect.size.width / 2.0))
self.loaderColor.setFill()
rectanglePath.fill()
}
Expand Down
6 changes: 3 additions & 3 deletions Source/Switch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ class Switch: UIView {
override init(frame: CGRect) {
super.init(frame: frame)

self.backgroundColor = UIColor.clearColor()
self.backgroundColor = UIColor.clear
}

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

override func drawRect(rect: CGRect) {
let rectanglePath = UIBezierPath(roundedRect: CGRectMake(0.0, 0.0, rect.size.width, rect.size.height), cornerRadius: rect.size.width / 2.0)
override func draw(_ rect: CGRect) {
let rectanglePath = UIBezierPath(roundedRect: CGRect(x: 0.0, y: 0.0, width: rect.size.width, height: rect.size.height), cornerRadius: rect.size.width / 2.0)
self.switchColor.setFill()
rectanglePath.fill()
}
Expand Down