|
@@ -33,6 +33,11 @@ public class FloatingButton: UIView {
|
|
let indicatorCounterFBBig = UIImageView()
|
|
let indicatorCounterFBBig = UIImageView()
|
|
|
|
|
|
var datePull: Date?
|
|
var datePull: Date?
|
|
|
|
+ var animationTimer = Timer()
|
|
|
|
+ var configAnim: Int = Int(Utils.getFloatingAnim().components(separatedBy: "~")[0]) ?? 1
|
|
|
|
+ var isLoopingAnim = (Int(Utils.getFloatingAnim().components(separatedBy: "~")[1]) ?? 1) == 1 ? true : false
|
|
|
|
+ var lastRunAnimationHrz = -1
|
|
|
|
+ var lastRunAnimationVrt = -1
|
|
|
|
|
|
var panGesture: UIPanGestureRecognizer?
|
|
var panGesture: UIPanGestureRecognizer?
|
|
var defaultWidthFB = (UIScreen.main.bounds.height * 0.5) / 7.5
|
|
var defaultWidthFB = (UIScreen.main.bounds.height * 0.5) / 7.5
|
|
@@ -110,6 +115,21 @@ public class FloatingButton: UIView {
|
|
backgroundColor = .clear
|
|
backgroundColor = .clear
|
|
frame = CGRect(x: UIScreen.main.bounds.width - defaultWidthFB, y: (UIScreen.main.bounds.height / 2) - defaultHeightFB, width: Utils.getConfigModeFB() == MODE_HORIZONTAL_SIDE_TAB ? UIScreen.main.bounds.width - defaultWidthFB : defaultWidthFB, height: defaultHeightFB)
|
|
frame = CGRect(x: UIScreen.main.bounds.width - defaultWidthFB, y: (UIScreen.main.bounds.height / 2) - defaultHeightFB, width: Utils.getConfigModeFB() == MODE_HORIZONTAL_SIDE_TAB ? UIScreen.main.bounds.width - defaultWidthFB : defaultWidthFB, height: defaultHeightFB)
|
|
|
|
|
|
|
|
+ if Utils.getConfigModeFB() == MODE_VERTICAL_ANIMATION || Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION {
|
|
|
|
+ if configAnim == 0 { //left to right
|
|
|
|
+ lastRunAnimationHrz = 1
|
|
|
|
+ } else if configAnim == 1 { //right to left
|
|
|
|
+ lastRunAnimationHrz = -1
|
|
|
|
+ } else if configAnim == 2 { //top to bottom
|
|
|
|
+ lastRunAnimationVrt = 1
|
|
|
|
+ } else if configAnim == 3 { //top to bottom
|
|
|
|
+ lastRunAnimationVrt = -1
|
|
|
|
+ }
|
|
|
|
+ if configAnim >= 0 && configAnim <= 3 {
|
|
|
|
+ checkDelayAnimation()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
let qmeraTap = UITapGestureRecognizer(target: self, action: #selector(qmeraTap))
|
|
let qmeraTap = UITapGestureRecognizer(target: self, action: #selector(qmeraTap))
|
|
qmeraTap.numberOfTouchesRequired = 1
|
|
qmeraTap.numberOfTouchesRequired = 1
|
|
nexilis_button.addGestureRecognizer(qmeraTap)
|
|
nexilis_button.addGestureRecognizer(qmeraTap)
|
|
@@ -189,6 +209,52 @@ public class FloatingButton: UIView {
|
|
UIApplication.shared.windows.first?.rootViewController?.view.addGestureRecognizer(tapGesture)
|
|
UIApplication.shared.windows.first?.rootViewController?.view.addGestureRecognizer(tapGesture)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private func checkDelayAnimation() {
|
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 3, execute: { [self] in
|
|
|
|
+ if !isShow {
|
|
|
|
+ animationTimer = Timer.scheduledTimer(timeInterval: 0.001, target: self, selector: #selector(runAnimation), userInfo: nil, repeats: true)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @objc func runAnimation(){
|
|
|
|
+ DispatchQueue.main.async { [self] in
|
|
|
|
+ if configAnim == 0 || configAnim == 1 {
|
|
|
|
+ if (lastRunAnimationHrz == -1 && frame.origin.x >= 0) || lastRunAnimationHrz == 1 && frame.origin.x <= UIScreen.main.bounds.width - defaultWidthFB {
|
|
|
|
+ if lastRunAnimationHrz == -1 {
|
|
|
|
+ frame.origin.x-=0.1
|
|
|
|
+ } else {
|
|
|
|
+ frame.origin.x+=0.1
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ lastRunAnimationHrz = lastRunAnimationHrz == 1 ? -1 : 1
|
|
|
|
+ if (lastRunAnimationHrz == -1 && configAnim == 1) || (lastRunAnimationHrz == 1 && configAnim == 0) {
|
|
|
|
+ animationTimer.invalidate()
|
|
|
|
+ if isLoopingAnim {
|
|
|
|
+ checkDelayAnimation()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (lastRunAnimationVrt == -1 && frame.origin.y >= 0) || lastRunAnimationVrt == 1 && frame.origin.y <= UIScreen.main.bounds.height - defaultHeightFB {
|
|
|
|
+ if lastRunAnimationVrt == -1 {
|
|
|
|
+ frame.origin.y-=0.1
|
|
|
|
+ } else {
|
|
|
|
+ frame.origin.y+=0.1
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ lastRunAnimationVrt = lastRunAnimationVrt == 1 ? -1 : 1
|
|
|
|
+ if (lastRunAnimationVrt == -1 && configAnim == 3) || (lastRunAnimationVrt == 1 && configAnim == 2) {
|
|
|
|
+ animationTimer.invalidate()
|
|
|
|
+ if isLoopingAnim {
|
|
|
|
+ checkDelayAnimation()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private func pullButton() {
|
|
private func pullButton() {
|
|
if datePull == nil || Int(Date().timeIntervalSince(datePull!)) >= 60 {
|
|
if datePull == nil || Int(Date().timeIntervalSince(datePull!)) >= 60 {
|
|
datePull = Date()
|
|
datePull = Date()
|
|
@@ -545,6 +611,7 @@ public class FloatingButton: UIView {
|
|
public func show(isShow: Bool) {
|
|
public func show(isShow: Bool) {
|
|
self.isShow = isShow
|
|
self.isShow = isShow
|
|
if isShow {
|
|
if isShow {
|
|
|
|
+ animationTimer.invalidate()
|
|
pullButton()
|
|
pullButton()
|
|
if indicatorCounterFBBig.isDescendant(of: nexilis_button) {
|
|
if indicatorCounterFBBig.isDescendant(of: nexilis_button) {
|
|
indicatorCounterFBBig.isHidden = true
|
|
indicatorCounterFBBig.isHidden = true
|
|
@@ -610,6 +677,9 @@ public class FloatingButton: UIView {
|
|
frame.origin.x = UIScreen.main.bounds.width - defaultWidthFB
|
|
frame.origin.x = UIScreen.main.bounds.width - defaultWidthFB
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
+ if Utils.getConfigModeFB() == MODE_VERTICAL_ANIMATION || Utils.getConfigModeFB() == MODE_HORIZONTAL_ANIMATION {
|
|
|
|
+ checkDelayAnimation()
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|