|
@@ -35,6 +35,11 @@ public class FloatingButton: UIView {
|
|
|
var datePull: Date?
|
|
|
|
|
|
var panGesture: UIPanGestureRecognizer?
|
|
|
+ var defaultWidthFB = (UIScreen.main.bounds.height * 0.5) / 7.5
|
|
|
+ var defaultHeightFB = (UIScreen.main.bounds.height * 0.5) / 7.5
|
|
|
+ let defaultWidthHeightMenuFB = (UIScreen.main.bounds.height * 0.45) / 7.5
|
|
|
+ let widthFBAnim = (UIScreen.main.bounds.height * 1) / 7.5
|
|
|
+ let heightFBAnim = (UIScreen.main.bounds.height * 1) / 7.5
|
|
|
|
|
|
public weak var mySettingDelegate: SettingMABDelegate?
|
|
|
|
|
@@ -51,18 +56,17 @@ public class FloatingButton: UIView {
|
|
|
}
|
|
|
|
|
|
private func commonInit() {
|
|
|
- backgroundColor = .clear
|
|
|
- frame = CGRect(x: UIScreen.main.bounds.width - 50, y: (UIScreen.main.bounds.height / 2) - 50, width: 50.0, height: 50.0)
|
|
|
-
|
|
|
panGesture = UIPanGestureRecognizer(target: self, action: #selector(draggedView(_:)))
|
|
|
addGestureRecognizer(panGesture!)
|
|
|
|
|
|
nexilis_button = UIImageView()
|
|
|
nexilis_button.translatesAutoresizingMaskIntoConstraints = false
|
|
|
nexilis_button.isUserInteractionEnabled = true
|
|
|
- if Utils.getIconDock() != nil {
|
|
|
+ if !Utils.getIconDock().isEmpty {
|
|
|
var dataImage: Data?
|
|
|
- if Utils.getIconDock()!.contains(".gif"){
|
|
|
+ if Utils.getIconDock().contains(".gif") {
|
|
|
+ defaultWidthFB = widthFBAnim
|
|
|
+ defaultHeightFB = heightFBAnim
|
|
|
nexilis_button.sd_setImage(with: URL(string: Utils.getIconCenterAnim()!)) { [self] (image, error, cacheType, imageURL) in
|
|
|
if let error = error {
|
|
|
//print("Error loading GIF: \(error.localizedDescription)")
|
|
@@ -84,6 +88,9 @@ public class FloatingButton: UIView {
|
|
|
nexilis_button.image = UIImage(named: "pb_button", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)
|
|
|
}
|
|
|
|
|
|
+ backgroundColor = .clear
|
|
|
+ frame = CGRect(x: UIScreen.main.bounds.width - defaultWidthFB, y: (UIScreen.main.bounds.height / 2) - defaultHeightFB, width: defaultWidthFB, height: defaultHeightFB)
|
|
|
+
|
|
|
let qmeraTap = UITapGestureRecognizer(target: self, action: #selector(qmeraTap))
|
|
|
qmeraTap.numberOfTouchesRequired = 1
|
|
|
nexilis_button.addGestureRecognizer(qmeraTap)
|
|
@@ -93,9 +100,9 @@ public class FloatingButton: UIView {
|
|
|
|
|
|
addSubview(nexilis_button)
|
|
|
|
|
|
- nexilis_button.widthAnchor.constraint(equalToConstant: 50.0).isActive = true
|
|
|
- nexilis_button.heightAnchor.constraint(equalToConstant: 50.0).isActive = true
|
|
|
- nexilis_button.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
|
|
|
+ nexilis_button.widthAnchor.constraint(equalToConstant: defaultWidthFB).isActive = true
|
|
|
+ nexilis_button.heightAnchor.constraint(equalToConstant: defaultHeightFB).isActive = true
|
|
|
+ nexilis_button.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
|
|
|
nexilis_button.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
|
|
|
|
|
|
scrollView = UIScrollView()
|
|
@@ -107,10 +114,16 @@ public class FloatingButton: UIView {
|
|
|
// scrollView.backgroundColor = .black.withAlphaComponent(0.25)
|
|
|
addSubview(scrollView)
|
|
|
|
|
|
- scrollView.widthAnchor.constraint(equalTo: widthAnchor).isActive = true
|
|
|
- scrollView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
|
|
|
+ scrollView.widthAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB + 10).isActive = true
|
|
|
scrollView.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
|
|
- scrollView.bottomAnchor.constraint(equalTo: nexilis_button.topAnchor).isActive = true
|
|
|
+ if Utils.getIconDock().contains(".gif") {
|
|
|
+ scrollView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
|
|
|
+ scrollView.leftAnchor.constraint(equalTo: nexilis_button.rightAnchor, constant: -20).isActive = true
|
|
|
+ scrollView.isHidden = true
|
|
|
+ } else {
|
|
|
+ scrollView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
|
|
|
+ scrollView.bottomAnchor.constraint(equalTo: nexilis_button.topAnchor).isActive = true
|
|
|
+ }
|
|
|
|
|
|
groupView = UIStackView()
|
|
|
groupView.translatesAutoresizingMaskIntoConstraints = false
|
|
@@ -119,7 +132,7 @@ public class FloatingButton: UIView {
|
|
|
|
|
|
scrollView.addSubview(groupView)
|
|
|
|
|
|
- groupView.widthAnchor.constraint(equalToConstant: 40).isActive = true
|
|
|
+ groupView.widthAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
|
|
|
groupView.topAnchor.constraint(equalTo: scrollView.topAnchor, constant: 5).isActive = true
|
|
|
groupView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor, constant: -5).isActive = true
|
|
|
groupView.leftAnchor.constraint(equalTo: scrollView.leftAnchor, constant: 6).isActive = true
|
|
@@ -164,7 +177,7 @@ public class FloatingButton: UIView {
|
|
|
let app_id = (json["app_id"] as? String) ?? ""
|
|
|
let icon = (json["icon"] as? String) ?? ""
|
|
|
let newButton = UIButton()
|
|
|
- newButton.heightAnchor.constraint(equalToConstant: 40).isActive = true
|
|
|
+ newButton.heightAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
|
|
|
newButton.translatesAutoresizingMaskIntoConstraints = false
|
|
|
if icon.isEmpty {
|
|
|
var indexTap = 0
|
|
@@ -226,14 +239,14 @@ public class FloatingButton: UIView {
|
|
|
|
|
|
func getDefaultButton() {
|
|
|
button_fb1 = UIButton()
|
|
|
- button_fb1.heightAnchor.constraint(equalToConstant: 40).isActive = true
|
|
|
+ button_fb1.heightAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
|
|
|
button_fb1.translatesAutoresizingMaskIntoConstraints = false
|
|
|
button_fb1.setImage(UIImage(named: "pb_button_cc", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
|
|
|
groupView.addArrangedSubview(button_fb1)
|
|
|
button_fb1.addTarget(self, action: #selector(fb1Tap), for: .touchUpOutside)
|
|
|
|
|
|
button_fb2 = UIButton()
|
|
|
- button_fb2.heightAnchor.constraint(equalToConstant: 40).isActive = true
|
|
|
+ button_fb2.heightAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
|
|
|
button_fb2.translatesAutoresizingMaskIntoConstraints = false
|
|
|
button_fb2.setImage(UIImage(named: "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
|
|
|
groupView.addArrangedSubview(button_fb2)
|
|
@@ -241,14 +254,14 @@ public class FloatingButton: UIView {
|
|
|
checkCounter()
|
|
|
|
|
|
button_fb3 = UIButton()
|
|
|
- button_fb3.heightAnchor.constraint(equalToConstant: 40).isActive = true
|
|
|
+ button_fb3.heightAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
|
|
|
button_fb3.translatesAutoresizingMaskIntoConstraints = false
|
|
|
button_fb3.setImage(UIImage(named: "pb_button_call", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
|
|
|
groupView.addArrangedSubview(button_fb3)
|
|
|
button_fb3.addTarget(self, action: #selector(fb3Tap), for: .touchUpOutside)
|
|
|
|
|
|
button_fb4 = UIButton()
|
|
|
- button_fb4.heightAnchor.constraint(equalToConstant: 40).isActive = true
|
|
|
+ button_fb4.heightAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
|
|
|
button_fb4.translatesAutoresizingMaskIntoConstraints = false
|
|
|
button_fb4.setImage(UIImage(named: "pb_button_stream", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
|
|
|
groupView.addArrangedSubview(button_fb4)
|
|
@@ -260,7 +273,7 @@ public class FloatingButton: UIView {
|
|
|
let widthScreen = size.width
|
|
|
let heightScreen = size.height
|
|
|
let minimumx = (widthScreen + 30) - widthScreen
|
|
|
- let maximumx = widthScreen - 30
|
|
|
+ var maximumx = widthScreen - 30
|
|
|
let translation = sender.translation(in: self)
|
|
|
var xPos = center.x + translation.x
|
|
|
var yPos = center.y + translation.y
|
|
@@ -272,8 +285,14 @@ public class FloatingButton: UIView {
|
|
|
xPos = maximumx
|
|
|
}
|
|
|
if(isShow) {
|
|
|
- let minimumy = CGFloat(120.5) //30
|
|
|
- let maximumy = heightScreen - 100
|
|
|
+ if Utils.getIconDock().contains(".gif") {
|
|
|
+ maximumx = widthScreen - 30 - defaultWidthHeightMenuFB
|
|
|
+ if (xPos > maximumx) {
|
|
|
+ xPos = maximumx
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let minimumy = (defaultWidthHeightMenuFB * 5) - defaultHeightFB
|
|
|
+ let maximumy = heightScreen - defaultHeightFB - 10
|
|
|
if(yPos < minimumy) {
|
|
|
yPos = minimumy
|
|
|
}
|
|
@@ -281,8 +300,8 @@ public class FloatingButton: UIView {
|
|
|
yPos = maximumy
|
|
|
}
|
|
|
} else {
|
|
|
- let minimumy = (heightScreen + 50) - heightScreen
|
|
|
- let maximumy = heightScreen - 20
|
|
|
+ let minimumy = defaultHeightFB - 50
|
|
|
+ let maximumy = heightScreen - defaultHeightFB + 50
|
|
|
if(yPos < minimumy) {
|
|
|
yPos = minimumy
|
|
|
}
|
|
@@ -417,7 +436,7 @@ public class FloatingButton: UIView {
|
|
|
if self.frame.origin.x < UIScreen.main.bounds.width / 2 - 30 {
|
|
|
self.frame.origin.x = 0
|
|
|
} else {
|
|
|
- self.frame.origin.x = UIScreen.main.bounds.width - 50
|
|
|
+ self.frame.origin.x = UIScreen.main.bounds.width - defaultWidthFB
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -428,13 +447,23 @@ public class FloatingButton: UIView {
|
|
|
if indicatorCounterFBBig.isDescendant(of: nexilis_button) {
|
|
|
indicatorCounterFBBig.isHidden = true
|
|
|
}
|
|
|
- let height = CGFloat(217) //40
|
|
|
- var yPosition = frame.origin.y - height + 50
|
|
|
+ var height = CGFloat((defaultWidthHeightMenuFB * 5) + defaultHeightFB + 5) //defaultWidthHeightMenuFB
|
|
|
+ var width = frame.width
|
|
|
+ var xPosition = frame.origin.x
|
|
|
+ if Utils.getIconDock().contains(".gif") {
|
|
|
+ height = CGFloat((defaultWidthHeightMenuFB * 3) + defaultHeightFB - 5)
|
|
|
+ width = frame.width + defaultWidthHeightMenuFB
|
|
|
+ if xPosition > UIScreen.main.bounds.width - defaultWidthFB - defaultWidthHeightMenuFB {
|
|
|
+ xPosition = UIScreen.main.bounds.width - defaultWidthFB - defaultWidthHeightMenuFB
|
|
|
+ }
|
|
|
+ scrollView.isHidden = false
|
|
|
+ }
|
|
|
+ var yPosition = frame.origin.y - height + defaultHeightFB
|
|
|
if yPosition <= 25 {
|
|
|
lastPosY = frame.origin.y
|
|
|
yPosition = 25
|
|
|
}
|
|
|
- frame = CGRect(x: frame.origin.x, y: yPosition, width: frame.width, height: height)
|
|
|
+ frame = CGRect(x: xPosition, y: yPosition, width: width, height: height)
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in
|
|
|
if isShow {
|
|
|
let countSubviewsAfter = groupView.subviews.count
|
|
@@ -447,12 +476,16 @@ public class FloatingButton: UIView {
|
|
|
if indicatorCounterFBBig.isDescendant(of: nexilis_button) {
|
|
|
indicatorCounterFBBig.isHidden = false
|
|
|
}
|
|
|
- let height = CGFloat(217) //40
|
|
|
- var yPosition = frame.origin.y + height - 50
|
|
|
+ var height = CGFloat((defaultWidthHeightMenuFB * 5) + defaultHeightFB + 5) //defaultWidthHeightMenuFB
|
|
|
+ if Utils.getIconDock().contains(".gif") {
|
|
|
+ height = CGFloat((defaultWidthHeightMenuFB * 3) + defaultHeightFB - 5)
|
|
|
+ scrollView.isHidden = true
|
|
|
+ }
|
|
|
+ var yPosition = frame.origin.y + height - defaultHeightFB
|
|
|
if lastPosY != nil {
|
|
|
yPosition = lastPosY!
|
|
|
}
|
|
|
- frame = CGRect(x: frame.origin.x, y: yPosition, width: frame.width, height: frame.width)
|
|
|
+ frame = CGRect(x: frame.origin.x, y: yPosition, width: defaultWidthFB, height: defaultHeightFB)
|
|
|
}
|
|
|
}
|
|
|
}
|