diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..c498d00 Binary files /dev/null and b/.DS_Store differ diff --git a/Example/.DS_Store b/Example/.DS_Store new file mode 100644 index 0000000..201d864 Binary files /dev/null and b/Example/.DS_Store differ diff --git a/Example/AppDelegate.swift b/Example/AppDelegate.swift index 58e00b8..9e254a7 100644 --- a/Example/AppDelegate.swift +++ b/Example/AppDelegate.swift @@ -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) { - } - - } diff --git a/Example/Assets.xcassets/AppIcon.appiconset/Contents.json b/Example/Assets.xcassets/AppIcon.appiconset/Contents.json index 118c98f..b8236c6 100644 --- a/Example/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/Example/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", diff --git a/Example/Base.lproj/LaunchScreen.storyboard b/Example/Base.lproj/LaunchScreen.storyboard index 1447b3c..2e4cb45 100644 --- a/Example/Base.lproj/LaunchScreen.storyboard +++ b/Example/Base.lproj/LaunchScreen.storyboard @@ -1,8 +1,9 @@ - + - + + @@ -14,10 +15,9 @@ - + - - + diff --git a/Example/Base.lproj/Storyboard.storyboard b/Example/Base.lproj/Storyboard.storyboard new file mode 100644 index 0000000..4085fcc --- /dev/null +++ b/Example/Base.lproj/Storyboard.storyboard @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example/DemoViewController.swift b/Example/DemoViewController.swift index 02a0dd4..c9a3b8f 100644 --- a/Example/DemoViewController.swift +++ b/Example/DemoViewController.swift @@ -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 - } } diff --git a/Example/Info.plist b/Example/Info.plist index d39a4da..9e0554a 100644 --- a/Example/Info.plist +++ b/Example/Info.plist @@ -24,6 +24,8 @@ UILaunchStoryboardName LaunchScreen + UIMainStoryboardFile + Storyboard UIRequiredDeviceCapabilities armv7 diff --git a/Loader.xcodeproj/project.pbxproj b/Loader.xcodeproj/project.pbxproj index 23f5753..0725b61 100644 --- a/Loader.xcodeproj/project.pbxproj +++ b/Loader.xcodeproj/project.pbxproj @@ -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 */; }; @@ -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; }; @@ -62,6 +64,7 @@ BE57DF1A1C149DF40071595C /* LaunchScreen.storyboard */, BE57DF1E1C149DF40071595C /* Info.plist */, BEE0F2851C149EDC00AFA2DE /* DemoViewController.swift */, + 88FA7E321D961802006C3CC8 /* Storyboard.storyboard */, ); path = Loader; sourceTree = ""; @@ -102,11 +105,12 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0710; - LastUpgradeCheck = 0710; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = Ekhoo; TargetAttributes = { BE3156731C149D0F00BA4E59 = { CreatedOnToolsVersion = 7.1; + LastSwiftMigration = 0800; }; }; }; @@ -135,6 +139,7 @@ files = ( BE57DF211C149DF40071595C /* Assets.xcassets in Resources */, BE57DF221C149DF40071595C /* LaunchScreen.storyboard in Resources */, + 88FA7E341D961802006C3CC8 /* Storyboard.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -155,6 +160,14 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ + 88FA7E321D961802006C3CC8 /* Storyboard.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 88FA7E331D961802006C3CC8 /* Base */, + ); + name = Storyboard.storyboard; + sourceTree = ""; + }; BE57DF1A1C149DF40071595C /* LaunchScreen.storyboard */ = { isa = PBXVariantGroup; children = ( @@ -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"; @@ -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"; @@ -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; @@ -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; }; @@ -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; }; diff --git a/Source/.DS_Store b/Source/.DS_Store new file mode 100644 index 0000000..b4f8732 Binary files /dev/null and b/Source/.DS_Store differ diff --git a/Source/Loader.swift b/Source/Loader.swift index 66ad73b..d369a04 100644 --- a/Source/Loader.swift +++ b/Source/Loader.swift @@ -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 { @@ -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!) } @@ -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 @@ -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() { @@ -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() } diff --git a/Source/Switch.swift b/Source/Switch.swift index cb9db76..41ef84e 100644 --- a/Source/Switch.swift +++ b/Source/Switch.swift @@ -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() }