From dfd3ae6f9cb108214fda47eba62b1516b5761662 Mon Sep 17 00:00:00 2001 From: Rusty Zarse Date: Wed, 21 Oct 2015 20:35:34 -0400 Subject: [PATCH 1/4] added FanUp to animation styles --- .../ViewController.swift | 20 ++++-- Pod/Classes/LiquidFloatingActionButton.swift | 62 +++++++++++-------- 2 files changed, 52 insertions(+), 30 deletions(-) diff --git a/Example/LiquidFloatingActionButton/ViewController.swift b/Example/LiquidFloatingActionButton/ViewController.swift index 09850f2..d2a013c 100644 --- a/Example/LiquidFloatingActionButton/ViewController.swift +++ b/Example/LiquidFloatingActionButton/ViewController.swift @@ -30,9 +30,9 @@ public class CustomCell : LiquidFloatingCell { label.font = UIFont(name: "Helvetica-Neue", size: 12) addSubview(label) label.snp_makeConstraints { make in - make.left.equalTo(self).offset(-80) + make.centerY.equalTo(self).offset(30) make.width.equalTo(75) - make.top.height.equalTo(self) + make.centerX.height.equalTo(self) } } } @@ -71,9 +71,19 @@ class ViewController: UIViewController, LiquidFloatingActionButtonDataSource, Li let floatingFrame2 = CGRect(x: 16, y: 16, width: 56, height: 56) let topLeftButton = createButton(floatingFrame2, .Down) - - self.view.addSubview(bottomRightButton) - self.view.addSubview(topLeftButton) + + let floatingFrameBottomMiddle = CGRect( + x: (self.view.frame.width - 56 - 16) / 2, + y: self.view.frame.height - 56 - 16, + width: 56, + height: 56 + ) + + let bottomMiddleButton = createButton(floatingFrameBottomMiddle, .FanUp) + + self.view.addSubview(bottomRightButton) + self.view.addSubview(topLeftButton) + self.view.addSubview(bottomMiddleButton) } override func didReceiveMemoryWarning() { diff --git a/Pod/Classes/LiquidFloatingActionButton.swift b/Pod/Classes/LiquidFloatingActionButton.swift index 45d0aaf..4f3c75f 100644 --- a/Pod/Classes/LiquidFloatingActionButton.swift +++ b/Pod/Classes/LiquidFloatingActionButton.swift @@ -25,6 +25,7 @@ public enum LiquidFloatingActionButtonAnimateStyle : Int { case Right case Left case Down + case FanUp } @IBDesignable @@ -284,9 +285,7 @@ class ActionBarBaseView : UIView { class CircleLiquidBaseView : ActionBarBaseView { - let openDuration: CGFloat = 0.6 - let closeDuration: CGFloat = 0.2 - let viscosity: CGFloat = 0.65 + let viscosity: CGFloat = 0.65 var animateStyle: LiquidFloatingActionButtonAnimateStyle = .Up var color: UIColor = UIColor(red: 82 / 255.0, green: 112 / 255.0, blue: 235 / 255.0, alpha: 1.0) { didSet { @@ -362,11 +361,19 @@ class CircleLiquidBaseView : ActionBarBaseView { } } - func update(delay: CGFloat, duration: CGFloat, f: (LiquidFloatingCell, Int, CGFloat) -> ()) { + func update() { if openingCells.isEmpty { return } + + var delay: CGFloat = 0.1 + var duration: CGFloat = 0.2 + if opening { + delay = 0.0 + duration = 0.6 + } + let maxDuration = duration + CGFloat(openingCells.count) * CGFloat(delay) let t = keyDuration let allRatio = easeInEaseOut(t / maxDuration) @@ -383,7 +390,8 @@ class CircleLiquidBaseView : ActionBarBaseView { let liquidCell = openingCells[i] let cellDelay = CGFloat(delay) * CGFloat(i) let ratio = easeInEaseOut((t - cellDelay) / duration) - f(liquidCell, i, ratio) + liquidCell.center = self.center.plus(self.differencePoint(liquidCell.frame.height, ratio: ratio, i: i)) + liquidCell.update(ratio, open: opening) } if let firstCell = openingCells.first { @@ -399,23 +407,23 @@ class CircleLiquidBaseView : ActionBarBaseView { } func updateOpen() { - update(0.1, duration: openDuration) { cell, i, ratio in - let posRatio = ratio > CGFloat(i) / CGFloat(self.openingCells.count) ? ratio : 0 - let distance = (cell.frame.height * 0.5 + CGFloat(i + 1) * cell.frame.height * 1.5) * posRatio - cell.center = self.center.plus(self.differencePoint(distance)) - cell.update(ratio, open: true) - } + update() } func updateClose() { - update(0, duration: closeDuration) { cell, i, ratio in - let distance = (cell.frame.height * 0.5 + CGFloat(i + 1) * cell.frame.height * 1.5) * (1 - ratio) - cell.center = self.center.plus(self.differencePoint(distance)) - cell.update(ratio, open: false) - } + update() } - func differencePoint(distance: CGFloat) -> CGPoint { + func differencePoint(cellLength: CGFloat, ratio: CGFloat, i: Int) -> CGPoint { + var adjustedRatio = 1 - ratio + + if opening { + adjustedRatio = ratio > CGFloat(i) / CGFloat(self.openingCells.count) ? ratio : 0 + } + + let totalDistance = cellLength * 0.5 + CGFloat(i + 1) * cellLength * 1.5 + let distance = totalDistance * adjustedRatio + switch animateStyle { case .Up: return CGPoint(x: 0, y: -distance) @@ -425,7 +433,16 @@ class CircleLiquidBaseView : ActionBarBaseView { return CGPoint(x: -distance, y: 0) case .Down: return CGPoint(x: 0, y: distance) - } + case .FanUp: + let totalSpread = (CGFloat(self.openingCells.count) * cellLength + cellLength) * adjustedRatio + let totalRise = cellLength * 0.75 * adjustedRatio + let count: CGFloat = CGFloat(self.openingCells.count) + let countLessOne: CGFloat = count > 1.0 ? count - 1.0 : 1.0 + let fanX = totalSpread * CGFloat(i) / countLessOne - totalSpread / 2.0 + let distanceFromCenter = totalRise / (count - (count + 1.0) / 2.0) * (CGFloat(i) + 1.0 - (count + 1.0) / 2.0) + let fanY = (cellLength * 1.5 + totalRise - abs(distanceFromCenter)) * adjustedRatio + return CGPoint(x: -fanX, y: -fanY) + } } func stop() { @@ -450,13 +467,8 @@ class CircleLiquidBaseView : ActionBarBaseView { } func didDisplayRefresh(displayLink: CADisplayLink) { - if opening { - keyDuration += CGFloat(displayLink.duration) - updateOpen() - } else { - keyDuration += CGFloat(displayLink.duration) - updateClose() - } + keyDuration += CGFloat(displayLink.duration) + updateOpen() } } From 10e80335ecfad157aca88e1abb40d24db3c2fa0c Mon Sep 17 00:00:00 2001 From: Rusty Zarse Date: Wed, 21 Oct 2015 20:43:11 -0400 Subject: [PATCH 2/4] update version and bundle id to avoid collisions --- Example/Pods/Pods.xcodeproj/project.pbxproj | 2 + .../LiquidFloatingActionButton/Info.plist | 40 +++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj index cef63ec..127244d 100644 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -828,6 +828,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MODULEMAP_FILE = "Target Support Files/LiquidFloatingActionButton/LiquidFloatingActionButton.modulemap"; MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_BUNDLE_IDENTIFIER = com.yoavlt.LiquidFloatingActionButton; PRODUCT_NAME = LiquidFloatingActionButton; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -882,6 +883,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MODULEMAP_FILE = "Target Support Files/LiquidFloatingActionButton/LiquidFloatingActionButton.modulemap"; MTL_ENABLE_DEBUG_INFO = YES; + PRODUCT_BUNDLE_IDENTIFIER = com.yoavlt.LiquidFloatingActionButton; PRODUCT_NAME = LiquidFloatingActionButton; SDKROOT = iphoneos; SKIP_INSTALL = YES; diff --git a/Example/Pods/Target Support Files/LiquidFloatingActionButton/Info.plist b/Example/Pods/Target Support Files/LiquidFloatingActionButton/Info.plist index c3f6ee3..6398b83 100644 --- a/Example/Pods/Target Support Files/LiquidFloatingActionButton/Info.plist +++ b/Example/Pods/Target Support Files/LiquidFloatingActionButton/Info.plist @@ -2,25 +2,25 @@ - CFBundleDevelopmentRegion - en - CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleIdentifier - org.cocoapods.${PRODUCT_NAME:rfc1034identifier} - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - ${PRODUCT_NAME} - CFBundlePackageType - FMWK - CFBundleShortVersionString - 0.1.1 - CFBundleSignature - ???? - CFBundleVersion - ${CURRENT_PROJECT_VERSION} - NSPrincipalClass - + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + FMWK + CFBundleShortVersionString + 0.1.2 + CFBundleSignature + ???? + CFBundleVersion + ${CURRENT_PROJECT_VERSION} + NSPrincipalClass + From 32f11eebcfa8c0c4c3fb7e837e9d28a8f676c768 Mon Sep 17 00:00:00 2001 From: Rusty Zarse Date: Wed, 21 Oct 2015 21:04:53 -0400 Subject: [PATCH 3/4] removed unnecessary functions --- Pod/Classes/LiquidFloatingActionButton.swift | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Pod/Classes/LiquidFloatingActionButton.swift b/Pod/Classes/LiquidFloatingActionButton.swift index 4f3c75f..e131cda 100644 --- a/Pod/Classes/LiquidFloatingActionButton.swift +++ b/Pod/Classes/LiquidFloatingActionButton.swift @@ -406,14 +406,6 @@ class CircleLiquidBaseView : ActionBarBaseView { bigEngine?.draw(baseLiquid!) } - func updateOpen() { - update() - } - - func updateClose() { - update() - } - func differencePoint(cellLength: CGFloat, ratio: CGFloat, i: Int) -> CGPoint { var adjustedRatio = 1 - ratio @@ -468,7 +460,7 @@ class CircleLiquidBaseView : ActionBarBaseView { func didDisplayRefresh(displayLink: CADisplayLink) { keyDuration += CGFloat(displayLink.duration) - updateOpen() + update() } } From 975ecd893e923428056d49d6119d3bf90114173a Mon Sep 17 00:00:00 2001 From: Rusty Zarse Date: Wed, 21 Oct 2015 21:42:17 -0400 Subject: [PATCH 4/4] deployment target 8.1 --- Example/Pods/Pods.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj index 127244d..d36d3e9 100644 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -824,7 +824,7 @@ GCC_PREFIX_HEADER = "Target Support Files/LiquidFloatingActionButton/LiquidFloatingActionButton-prefix.pch"; INFOPLIST_FILE = "Target Support Files/LiquidFloatingActionButton/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.3; + IPHONEOS_DEPLOYMENT_TARGET = 8.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MODULEMAP_FILE = "Target Support Files/LiquidFloatingActionButton/LiquidFloatingActionButton.modulemap"; MTL_ENABLE_DEBUG_INFO = NO; @@ -879,7 +879,7 @@ GCC_PREFIX_HEADER = "Target Support Files/LiquidFloatingActionButton/LiquidFloatingActionButton-prefix.pch"; INFOPLIST_FILE = "Target Support Files/LiquidFloatingActionButton/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.3; + IPHONEOS_DEPLOYMENT_TARGET = 8.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MODULEMAP_FILE = "Target Support Files/LiquidFloatingActionButton/LiquidFloatingActionButton.modulemap"; MTL_ENABLE_DEBUG_INFO = YES;