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/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj index cef63ec..d36d3e9 100644 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -824,10 +824,11 @@ 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; + PRODUCT_BUNDLE_IDENTIFIER = com.yoavlt.LiquidFloatingActionButton; PRODUCT_NAME = LiquidFloatingActionButton; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -878,10 +879,11 @@ 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; + 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 + diff --git a/Pod/Classes/LiquidFloatingActionButton.swift b/Pod/Classes/LiquidFloatingActionButton.swift index 45d0aaf..e131cda 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 { @@ -398,24 +406,16 @@ class CircleLiquidBaseView : ActionBarBaseView { bigEngine?.draw(baseLiquid!) } - 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) - } - } - - 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) - } - } - - 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 +425,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 +459,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) + update() } }