Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update LiquidFloatingActionButton.swift #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions Pod/Classes/LiquidFloatingActionButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import QuartzCore
@objc public protocol LiquidFloatingActionButtonDelegate {
// selected method
optional func liquidFloatingActionButton(liquidFloatingActionButton: LiquidFloatingActionButton, didSelectItemAtIndex index: Int)
optional func didTapped(liquidFloatingActionButton: LiquidFloatingActionButton)
optional func didLongTapped(liquidFloatingActionButton: LiquidFloatingActionButton)
}

public enum LiquidFloatingActionButtonAnimateStyle : Int {
Expand Down Expand Up @@ -47,6 +49,9 @@ public class LiquidFloatingActionButton : UIView {
public var dataSource: LiquidFloatingActionButtonDataSource?

public var responsible = true
private var longTapTimer : NSTimer?
public var longTapTime = 2.0

public var isClosed: Bool {
get {
return plusRotation == 0
Expand Down Expand Up @@ -195,13 +200,16 @@ public class LiquidFloatingActionButton : UIView {
// MARK: Events
public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
self.touching = true
self.longTapTimer = NSTimer.scheduledTimerWithTimeInterval(self.longTapTime, target: self, selector: "didLongTapped", userInfo: nil, repeats: false)
setNeedsDisplay()
}

public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
if(self.touching == true){
setNeedsDisplay()
didTapped()
}
self.touching = false
setNeedsDisplay()
didTapped()
}

public override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
Expand Down Expand Up @@ -240,13 +248,22 @@ public class LiquidFloatingActionButton : UIView {
}

private func didTapped() {
longTapTimer?.invalidate()
delegate!.didTapped!(self)
if isClosed {
open()
} else {
close()
}
}

private func didLongTapped(){
self.touching = false
if isClosed{
delegate!.didLongTapped!(self)
}
}

public func didTappedCell(target: LiquidFloatingCell) {
if let source = dataSource {
let cells = cellArray()
Expand Down Expand Up @@ -544,4 +561,4 @@ public class LiquidFloatingCell : LiquittableCircle {
actionButton?.didTappedCell(self)
}

}
}