Skip to content

Commit

Permalink
Display fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joedaniels29 committed Sep 7, 2016
1 parent 4317e8d commit b4985cd
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 62 deletions.
6 changes: 0 additions & 6 deletions .travis.yml
Expand Up @@ -6,13 +6,7 @@ env:
- LANG=en_US.UTF-8
- PROJECT=SwiftClock.xcodeproj
- IOS_FRAMEWORK_SCHEME="10Clock"
# - OSX_FRAMEWORK_SCHEME="Alamofire OSX"
# - TVOS_FRAMEWORK_SCHEME="Alamofire tvOS"
# - WATCHOS_FRAMEWORK_SCHEME="Alamofire watchOS"
- IOS_SDK=iphonesimulator9.3
# - OSX_SDK=macosx10.11
# - TVOS_SDK=appletvsimulator9.2
# - WATCHOS_SDK=watchsimulator2.2
- EXAMPLE_SCHEME="SwiftClock"
matrix:
- DESTINATION="OS=8.1,name=iPhone 4S" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="YES"
Expand Down
137 changes: 137 additions & 0 deletions 10Clock.podspec.erb
@@ -0,0 +1,137 @@
#
# Be sure to run `pod spec lint SwiftClock.podspec' to ensure this is a
# valid spec and to remove all comments including this before submitting the spec.
#
# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#

Pod::Spec.new do |s|

# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# These will help people to find your library, and whilst it
# can feel like a chore to fill in it's definitely to your advantage. The
# summary should be tweet-length, and the description more in depth.
#

s.name = "10Clock"
s.version = "<%=version%>"
s.summary = "Beautiful iOS Time Picker inspired by the ios 10 \"Bedtime\" Timer."

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!
s.description = <<-DESC
This Control is a beautiful time-of-day picker heavily inspired by the iOS 10 "Bedtime" timer.
DESC

s.homepage = "https://github.com/joedaniels29/10Clock"
# s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"


# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Licensing your code is important. See http://choosealicense.com for more info.
# CocoaPods will detect a license file if there is a named LICENSE*
# Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
#

#s.license = "MIT"
s.license = { :type => "MIT", :file => "LICENSE" }


# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the authors of the library, with email addresses. Email addresses
# of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
# accepts just a name if you'd rather not provide an email address.
#
# Specify a social_media_url where others can refer to, for example a twitter
# profile URL.
#
s.author = { "Joe" => "joedaniels29@me.com" }
# Or just: s.author = "Joe"
# s.authors = { "Joe" => "joedaniels29@me.com" }
s.social_media_url = "http://twitter.com/joedaniels29"

# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If this Pod runs only on iOS or OS X, then specify the platform and
# the deployment target. You can optionally include the target after the platform.
#

# s.platform = :ios
s.platform = :ios, "9.0"

# When using multiple platforms
# s.ios.deployment_target = "5.0"
# s.osx.deployment_target = "10.7"
# s.watchos.deployment_target = "2.0"
# s.tvos.deployment_target = "9.0"


# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the location from where the source should be retrieved.
# Supports git, hg, bzr, svn and HTTP.
#

s.source = { :git => "https://github.com/joedaniels29/10Clock.git", :tag => "v" + s.version.to_s }


# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# CocoaPods is smart about how it includes source code. For source files
# giving a folder will include any swift, h, m, mm, c & cpp files.
# For header files it will include any header in the folder.
# Not including the public_header_files will make all headers public.
#

s.source_files = "Classes", "10Clock/*.swift"
s.exclude_files = "SwiftClock/*"

# s.public_header_files = "Classes/**/*.h"


# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# A list of resources included with the Pod. These are copied into the
# target bundle with a build phase script. Anything else will be cleaned.
# You can preserve files from being cleaned, please don't preserve
# non-essential files like tests, examples and documentation.
#

# s.resource = "icon.png"
# s.resources = "Resources/*.png"

# s.preserve_paths = "FilesToSave", "MoreFilesToSave"


# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Link your library with frameworks, or libraries. Libraries do not include
# the lib prefix of their name.
#

#s.framework = "CoreAnimation"
# s.frameworks = "SomeFramework", "AnotherFramework"

# s.library = "iconv"
# s.libraries = "iconv", "xml2"


# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If your library depends on compiler flags you can set them in the xcconfig hash
# where they will only apply to your library. If you depend on other Podspecs
# you can include multiple dependencies to ensure it works.

# s.requires_arc = true

# s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
# s.dependency "Archimedes", ""

end
65 changes: 31 additions & 34 deletions 10Clock/Clock.swift
Expand Up @@ -9,7 +9,7 @@
import Foundation
import UIKit

public protocol ClockDelegate {
@objc public protocol ClockDelegate {
func timesChanged(clock:Clock, startDate:NSDate, endDate:NSDate ) -> ()

}
Expand Down Expand Up @@ -90,7 +90,7 @@ public class Clock : UIControl{

var trackWidth:CGFloat {return pathWidth }
func proj(theta:Angle) -> CGPoint{
let center = CGPointMake( self.layer.frame.midX, self.layer.frame.midY)
let center = self.layer.center
return CGPointMake(center.x + trackRadius * cos(theta) ,
center.y - trackRadius * sin(theta) )
}
Expand Down Expand Up @@ -145,7 +145,7 @@ public class Clock : UIControl{
return CGRectInset(self.inset, reInsetAmount, reInsetAmount)
}
var titleTextInset:CGRect{
let reInsetAmount = trackWidth / 2 + 4 * internalShift
let reInsetAmount = trackWidth.checked / 2 + 4 * internalShift
return CGRectInset(self.inset, reInsetAmount, reInsetAmount)
}
var trackRadius:CGFloat { return inset.height / 2}
Expand All @@ -164,28 +164,24 @@ public class Clock : UIControl{

func update() {
let mm = min(self.layer.bounds.size.height, self.layer.bounds.size.width)
self.layer.bounds.size = CGSize(width: mm, height: mm)
CATransaction.begin()
self.layer.size = CGSize(width: mm, height: mm)
self.layer.position = self.bounds.center
strokeColor = tintColor
overallPathLayer.frame = self.layer.bounds
overallPathLayer.position = self.layer.position
gradientLayer.frame = self.layer.bounds
gradientLayer.position = self.layer.position
trackLayer.frame.size = inset.size
trackLayer.position = self.layer.position

pathLayer.frame = inset
pathLayer.position = self.layer.position
repLayer.frame = internalInset
repLayer2.frame = internalInset
numeralsLayer.frame = numeralInset

pathLayer.lineWidth = pathWidth
trackLayer.lineWidth = trackWidth
overallPathLayer.occupation = layer.occupation
gradientLayer.occupation = layer.occupation

trackLayer.occupation = (inset.size, layer.center)

pathLayer.occupation = (inset.size, overallPathLayer.center)
repLayer.occupation = (internalInset.size, overallPathLayer.center)
repLayer2.occupation = (internalInset.size, overallPathLayer.center)
numeralsLayer.occupation = (numeralInset.size, layer.center)

trackLayer.fillColor = UIColor.clearColor().CGColor
pathLayer.fillColor = UIColor.clearColor().CGColor
CATransaction.begin()


CATransaction.setValue(kCFBooleanTrue, forKey: kCATransactionDisableActions)
updateGradientLayer()
updateTrackLayerPath()
Expand All @@ -195,6 +191,7 @@ public class Clock : UIControl{
updateWatchFaceNumerals()
updateWatchFaceTitle()
CATransaction.commit()

}
func updateGradientLayer() {
gradientLayer.colors = [UIColor ( red: 0.7011, green: 0.0, blue: 1.0, alpha: 1.0 ).CGColor, UIColor ( red: 0.9992, green: 0.0, blue: 0.5578, alpha: 1.0 ).CGColor]
Expand All @@ -206,8 +203,8 @@ public class Clock : UIControl{
let circle = UIBezierPath(
ovalInRect: CGRect(
origin:CGPoint(x: 0, y: 00),
size: CGSize(width:trackLayer.frame.width,
height: trackLayer.frame.width)))
size: CGSize(width:trackLayer.size.width,
height: trackLayer.size.width)))
trackLayer.lineWidth = pathWidth
trackLayer.path = circle.CGPath

Expand All @@ -216,7 +213,7 @@ public class Clock : UIControl{
update()
}
func updatePathLayerPath() {
let arcCenter = CGPoint(x: pathLayer.bounds.width / 2.0, y: pathLayer.bounds.height / 2.0)
let arcCenter = pathLayer.center
pathLayer.fillColor = UIColor.clearColor().CGColor
pathLayer.lineWidth = pathWidth
// print("start = \(headAngle), end = \(tailAngle)")
Expand Down Expand Up @@ -251,8 +248,8 @@ public class Clock : UIControl{
let iCircle = UIBezierPath(ovalInRect: CGRect(origin: CGPoint(x: 0, y:0), size: iSize)).CGPath
tailLayer.path = circle
headLayer.path = circle
tailLayer.bounds.size = size
headLayer.bounds.size = size
tailLayer.size = size
headLayer.size = size
tailLayer.position = tailPoint
headLayer.position = headPoint
topTailLayer.position = tailPoint
Expand All @@ -261,16 +258,16 @@ public class Clock : UIControl{
tailLayer.fillColor = UIColor.greenColor().CGColor
topTailLayer.path = iCircle
topHeadLayer.path = iCircle
topTailLayer.bounds.size = iSize
topHeadLayer.bounds.size = iSize
topTailLayer.size = iSize
topHeadLayer.size = iSize
topHeadLayer.fillColor = UIColor ( red: 0.1172, green: 0.1172, blue: 0.1172, alpha: 1.0 ).CGColor
topTailLayer.fillColor = UIColor ( red: 0.0645, green: 0.0645, blue: 0.0645, alpha: 1.0 ).CGColor
topHeadLayer.sublayers?.forEach({$0.removeFromSuperlayer()})
topTailLayer.sublayers?.forEach({$0.removeFromSuperlayer()})
let stText = tlabel("Sleep")
let endText = tlabel("Wake")
stText.position = topHeadLayer.bounds.center
endText.position = topTailLayer.bounds.center
stText.position = topHeadLayer.center
endText.position = topTailLayer.center
topHeadLayer.addSublayer(stText)
topTailLayer.addSublayer(endText)
}
Expand All @@ -281,7 +278,7 @@ public class Clock : UIControl{
let f = UIFont.preferredFontForTextStyle(UIFontTextStyleCaption2)
let cgFont = CTFontCreateWithName(f.fontName, f.pointSize/2,nil)
let startPos = CGPoint(x: numeralsLayer.bounds.midX, y: 15)
let origin = numeralsLayer.bounds.center
let origin = numeralsLayer.center
let step = (2 * M_PI) / 12
for i in (1 ... 12){
let l = CATextLayer()
Expand All @@ -293,7 +290,7 @@ public class Clock : UIControl{
l.font = cgFont
l.string = "\(i)"
l.foregroundColor = UIColor.lightGrayColor().CGColor
l.position = CGVector(from:origin, to:startPos).rotate( CGFloat(Double(i) * step)).add(origin.vector).point
l.position = CGVector(from:origin, to:startPos).rotate( CGFloat(Double(i) * step)).add(origin.vector).point.checked
numeralsLayer.addSublayer(l)
}
}
Expand All @@ -311,7 +308,7 @@ public class Clock : UIControl{
computedTailAngle += (headAngle > computedTailAngle ? twoPi : 0)
let fiveMinIncrements = Int( (abs(tailAngle - headAngle) / twoPi) * 12 /*hrs*/ * 12 /*5min increments*/)
titleTextLayer.string = "\(fiveMinIncrements / 12)hr \((fiveMinIncrements % 12) * 5)min"
titleTextLayer.position = gradientLayer.bounds.center
titleTextLayer.position = gradientLayer.center

}
func tick() -> CAShapeLayer{
Expand Down Expand Up @@ -414,8 +411,8 @@ public class Clock : UIControl{

let pp: (() -> Angle, Angle->()) -> (CGPoint) -> () = { g, s in
return { p in
let c = self.layer.frame.center
let computedP = CGPointMake(p.x, self.layer.frame.height - p.y)
let c = self.layer.center
let computedP = CGPointMake(p.x, self.layer.bounds.height - p.y)
let v1 = CGVector(from: c, to: computedP)
let v2 = CGVector(angle:g())

Expand Down
21 changes: 21 additions & 0 deletions 10Clock/CoreAnimation.swift
@@ -0,0 +1,21 @@
//
// Created by Joseph Daniels on 07/09/16.
// Copyright (c) 2016 Joseph Daniels. All rights reserved.
//

import Foundation
import UIKit
import QuartzCore
extension CALayer{
var size:CGSize{
get{ return self.bounds.size.checked }
set{ return self.bounds.size = newValue }
}
var occupation:(CGSize, CGPoint) {
get{ return (size, self.center.checked) }
set{ size = newValue.0; position = newValue.1 }
}
var center:CGPoint{
get{ return self.bounds.center.checked }
}
}

0 comments on commit b4985cd

Please sign in to comment.