Skip to content

Commit

Permalink
Merge pull request #11 from ykyouhei/develop
Browse files Browse the repository at this point in the history
v1.0.4
  • Loading branch information
ykyouhei authored Jul 20, 2016
2 parents b810df5 + 5eb70b6 commit 1e6d095
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 18 deletions.
7 changes: 6 additions & 1 deletion Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0630;
LastUpgradeCheck = 0730;
ORGANIZATIONNAME = "Kyouhei Yamaguchi";
TargetAttributes = {
419E22D71B2D85CF00DA0E57 = {
Expand Down Expand Up @@ -290,6 +290,7 @@
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -356,6 +357,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = Example/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.ykyouhei.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
Expand All @@ -366,6 +368,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = Example/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.ykyouhei.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Expand All @@ -384,6 +387,7 @@
);
INFOPLIST_FILE = ExampleTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.ykyouhei.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example";
};
Expand All @@ -399,6 +403,7 @@
);
INFOPLIST_FILE = ExampleTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.ykyouhei.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example";
};
Expand Down
6 changes: 3 additions & 3 deletions Example/Example/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand Down Expand Up @@ -70,7 +70,7 @@
<color key="value" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="rotateAnimateDuration">
<real key="value" value="0.10000000000000001"/>
<real key="value" value="5"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
Expand Down
2 changes: 1 addition & 1 deletion Example/Example/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.ykyouhei.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
2 changes: 1 addition & 1 deletion Example/ExampleTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.ykyouhei.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
2 changes: 1 addition & 1 deletion KYShutterButton.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "KYShutterButton"
s.version = "1.0.3"
s.version = "1.0.4"
s.summary = "KYShutterButton is a custom button that is similar to the shutter button of the camera app"
s.homepage = "https://github.com/ykyouhei/KYShutterButton"
s.license = "MIT"
Expand Down
64 changes: 53 additions & 11 deletions KYShutterButton/Classes/KYShutterButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public class KYShutterButton: UIButton {
switch buttonState {
case .Normal:
if shutterType == .TimeLapse {
_progressLayer.removeAllAnimations()
_rotateLayer.removeAllAnimations()
p_removeTimeLapseAnimations()
}
animation.toValue = _circlePath.CGPath
_circleLayer.addAnimation(animation, forKey: "path-anim")
Expand All @@ -106,11 +105,7 @@ public class KYShutterButton: UIButton {
_circleLayer.addAnimation(animation, forKey: "path-anim")
_circleLayer.path = _roundRectPath.CGPath
if shutterType == .TimeLapse {
_progressLayer.addAnimation(_startProgressAnimation, forKey: "start-anim")
_rotateLayer.addAnimation(_startRotateAnimation, forKey: "rotate-anim")
_progressLayer.addAnimation(_recordingAnimation, forKey: "recording-anim")
_rotateLayer.addAnimation(_recordingRotateAnimation, forKey: "recordingRotate-anim")
_progressLayer.path = p_arcPathWithProgress(1.0).CGPath
p_addTimeLapseAnimations()
}
}
}
Expand Down Expand Up @@ -179,12 +174,9 @@ public class KYShutterButton: UIButton {

lazy private var _rotateLayer: CAShapeLayer = {
let layer = CAShapeLayer()
let subPath = UIBezierPath()
subPath.moveToPoint(CGPointMake(self.bounds.width/2, 0))
subPath.addLineToPoint(CGPointMake(self.bounds.width/2, self._arcWidth))
layer.strokeColor = self.progressColor.CGColor
layer.lineWidth = 1
layer.path = subPath.CGPath
layer.path = self._rotatePath.CGPath
layer.frame = self.bounds
return layer
}()
Expand All @@ -197,6 +189,16 @@ public class KYShutterButton: UIButton {
)
}

private var _arcPath: UIBezierPath {
return UIBezierPath(
arcCenter: CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)),
radius: self.bounds.width/2 - self._arcWidth/2,
startAngle: -CGFloat(M_PI_2),
endAngle: CGFloat(M_PI*2.0) - CGFloat(M_PI_2),
clockwise: true
)
}

private var _roundRectPath: UIBezierPath {
let side = bounds.width * 0.4242
return UIBezierPath(
Expand All @@ -205,6 +207,13 @@ public class KYShutterButton: UIButton {
)
}

private var _rotatePath: UIBezierPath {
let path = UIBezierPath()
path.moveToPoint(CGPointMake(self.bounds.width/2, 0))
path.addLineToPoint(CGPointMake(self.bounds.width/2, self._arcWidth))
return path
}

private var _startProgressAnimation: CAKeyframeAnimation {
let frameCount = 60
var paths = [CGPath]()
Expand Down Expand Up @@ -286,15 +295,35 @@ public class KYShutterButton: UIButton {
super.layoutSubviews()
if _arcLayer.superlayer != layer {
layer.addSublayer(_arcLayer)
} else {
_arcLayer.path = _arcPath.CGPath
}

if _progressLayer.superlayer != layer {
layer.addSublayer(_progressLayer)
} else {
_progressLayer.path = p_arcPathWithProgress(1).CGPath
}

if _rotateLayer.superlayer != layer {
layer.insertSublayer(_rotateLayer, atIndex: 0)
} else {
_rotateLayer.path = _rotatePath.CGPath
_rotateLayer.frame = self.bounds
}

if _circleLayer.superlayer != layer {
layer.addSublayer(_circleLayer)
} else {
switch buttonState {
case .Normal: _circleLayer.path = _circlePath.CGPath
case .Recording: _circleLayer.path = _roundRectPath.CGPath
}
}

if shutterType == .TimeLapse && buttonState == .Recording {
p_removeTimeLapseAnimations()
p_addTimeLapseAnimations()
}
}

Expand All @@ -307,6 +336,19 @@ public class KYShutterButton: UIButton {
// MARK: - Method
/**************************************************************************/

private func p_addTimeLapseAnimations() {
_progressLayer.addAnimation(_startProgressAnimation, forKey: "start-anim")
_rotateLayer.addAnimation(_startRotateAnimation, forKey: "rotate-anim")
_progressLayer.addAnimation(_recordingAnimation, forKey: "recording-anim")
_rotateLayer.addAnimation(_recordingRotateAnimation, forKey: "recordingRotate-anim")
_progressLayer.path = p_arcPathWithProgress(1.0).CGPath
}

private func p_removeTimeLapseAnimations() {
_progressLayer.removeAllAnimations()
_rotateLayer.removeAllAnimations()
}

private func p_arcPathWithProgress(progress: CGFloat, clockwise: Bool = true) -> UIBezierPath {
let diameter = 2*CGFloat(M_PI)*(self.bounds.width/2 - self._arcWidth/3)
let startAngle = clockwise ?
Expand Down

0 comments on commit 1e6d095

Please sign in to comment.