Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| db7ca734e9 | |||
| f4f645548d | |||
| c520680100 | |||
| 04e27502df | |||
| 9f211f33af | |||
| 083d952ad7 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'CircleMenu'
|
||||
s.version = '3.0.1'
|
||||
s.version = '3.0.3'
|
||||
s.summary = 'Amazing animation with buttons'
|
||||
s.homepage = 'https://github.com/Ramotion/circle-menu'
|
||||
s.license = 'MIT'
|
||||
|
||||
@@ -88,6 +88,20 @@ open class CircleMenu: UIButton {
|
||||
@IBInspectable open var distance: Float = 100
|
||||
/// Delay between show buttons
|
||||
@IBInspectable open var showDelay: Double = 0
|
||||
/// Start angle of the circle
|
||||
@IBInspectable open var startAngle: Float = 0
|
||||
/// End angle of the circle
|
||||
@IBInspectable open var endAngle: Float = 360
|
||||
|
||||
// Pop buttons radius, if nil use center button size
|
||||
open var subButtonsRadius: CGFloat?
|
||||
|
||||
// Show buttons event
|
||||
open var showButtonsEvent: UIControlEvents = UIControlEvents.touchUpInside {
|
||||
didSet {
|
||||
addActions(newEvent: showButtonsEvent, oldEvent: oldValue)
|
||||
}
|
||||
}
|
||||
|
||||
/// The object that acts as the delegate of the circle menu.
|
||||
@IBOutlet open var delegate: AnyObject? // CircleMenuDelegate?
|
||||
@@ -140,7 +154,7 @@ open class CircleMenu: UIButton {
|
||||
}
|
||||
|
||||
fileprivate func commonInit() {
|
||||
addActions()
|
||||
addActions(newEvent: showButtonsEvent)
|
||||
|
||||
customNormalIconView = addCustomImageView(state: UIControlState())
|
||||
|
||||
@@ -167,7 +181,7 @@ open class CircleMenu: UIButton {
|
||||
|
||||
buttonsAnimationIsShow(isShow: false, duration: duration, hideDelay: hideDelay)
|
||||
|
||||
tapBounceAnimation()
|
||||
tapBounceAnimation(duration: 0.5)
|
||||
tapRotatedAnimation(0.3, isSelected: false)
|
||||
}
|
||||
|
||||
@@ -197,12 +211,18 @@ open class CircleMenu: UIButton {
|
||||
fileprivate func createButtons(platform: UIView) -> [UIButton] {
|
||||
var buttons = [UIButton]()
|
||||
|
||||
let step: Float = 360.0 / Float(buttonsCount)
|
||||
let step = getArcStep()
|
||||
for index in 0 ..< buttonsCount {
|
||||
|
||||
let angle: Float = Float(index) * step
|
||||
let angle: Float = startAngle + Float(index) * step
|
||||
let distance = Float(bounds.size.height / 2.0)
|
||||
let button = Init(CircleMenuButton(size: bounds.size, platform: platform, distance: distance, angle: angle)) {
|
||||
let buttonSize: CGSize
|
||||
if let subButtonsRadius = self.subButtonsRadius {
|
||||
buttonSize = CGSize(width: subButtonsRadius * 2, height: subButtonsRadius * 2)
|
||||
} else {
|
||||
buttonSize = bounds.size
|
||||
}
|
||||
let button = Init(CircleMenuButton(size: buttonSize, platform: platform, distance: distance, angle: angle)) {
|
||||
$0.tag = index
|
||||
$0.addTarget(self, action: #selector(CircleMenu.buttonHandler(_:)), for: UIControlEvents.touchUpInside)
|
||||
$0.alpha = 0
|
||||
@@ -275,13 +295,37 @@ open class CircleMenu: UIButton {
|
||||
|
||||
// MARK: configure
|
||||
|
||||
fileprivate func addActions() {
|
||||
addTarget(self, action: #selector(CircleMenu.onTap), for: UIControlEvents.touchUpInside)
|
||||
fileprivate func addActions(newEvent: UIControlEvents, oldEvent: UIControlEvents? = nil) {
|
||||
if let oldEvent = oldEvent { removeTarget(self, action: #selector(CircleMenu.onTap), for: oldEvent) }
|
||||
addTarget(self, action: #selector(CircleMenu.onTap), for: newEvent)
|
||||
}
|
||||
|
||||
/**
|
||||
Retrieves the incremental lengths between buttons. If the arc length is 360 degrees or more, the increments
|
||||
will evenly space out in a full circle. If the arc length is less than 360 degrees, the last button will be
|
||||
placed on the endAngle.
|
||||
*/
|
||||
fileprivate func getArcStep() -> Float {
|
||||
var arcLength = endAngle - startAngle
|
||||
var stepCount = buttonsCount
|
||||
|
||||
if arcLength < 360 {
|
||||
stepCount -= 1
|
||||
} else if arcLength > 360 {
|
||||
arcLength = 360
|
||||
}
|
||||
|
||||
return arcLength / Float(stepCount)
|
||||
}
|
||||
|
||||
// MARK: actions
|
||||
|
||||
private var isBounceAnimating: Bool = false
|
||||
|
||||
@objc func onTap() {
|
||||
guard isBounceAnimating == false else { return }
|
||||
isBounceAnimating = true
|
||||
|
||||
if buttonsIsShown() == false {
|
||||
let platform = createPlatform()
|
||||
buttons = createButtons(platform: platform)
|
||||
@@ -291,7 +335,7 @@ open class CircleMenu: UIButton {
|
||||
let duration = isShow ? 0.5 : 0.2
|
||||
buttonsAnimationIsShow(isShow: isShow, duration: duration)
|
||||
|
||||
tapBounceAnimation()
|
||||
tapBounceAnimation(duration: 0.5) { [weak self] _ in self?.isBounceAnimating = false }
|
||||
tapRotatedAnimation(0.3, isSelected: isShow)
|
||||
}
|
||||
|
||||
@@ -299,9 +343,16 @@ open class CircleMenu: UIButton {
|
||||
guard let platform = self.platform else { return }
|
||||
|
||||
delegate?.circleMenu?(self, buttonWillSelected: sender, atIndex: sender.tag)
|
||||
|
||||
let strokeWidth: CGFloat
|
||||
if let radius = self.subButtonsRadius {
|
||||
strokeWidth = radius * 2
|
||||
} else {
|
||||
strokeWidth = bounds.size.height
|
||||
}
|
||||
|
||||
let circle = CircleMenuLoader(radius: CGFloat(distance),
|
||||
strokeWidth: bounds.size.height,
|
||||
strokeWidth: strokeWidth,
|
||||
platform: platform,
|
||||
color: sender.backgroundColor)
|
||||
|
||||
@@ -311,7 +362,8 @@ open class CircleMenu: UIButton {
|
||||
}
|
||||
|
||||
if let buttons = buttons {
|
||||
circle.fillAnimation(duration, startAngle: -90 + Float(360 / buttons.count) * Float(sender.tag)) { [weak self] in
|
||||
let step = getArcStep()
|
||||
circle.fillAnimation(duration, startAngle: -90 + startAngle + step * Float(sender.tag)) { [weak self] in
|
||||
self?.buttons?.forEach { $0.alpha = 0 }
|
||||
}
|
||||
circle.hideAnimation(0.5, delay: duration) { [weak self] in
|
||||
@@ -337,13 +389,12 @@ open class CircleMenu: UIButton {
|
||||
return
|
||||
}
|
||||
|
||||
let step: Float = 360.0 / Float(buttonsCount)
|
||||
let step = getArcStep()
|
||||
for index in 0 ..< buttonsCount {
|
||||
guard case let button as CircleMenuButton = buttons[index] else { continue }
|
||||
let angle: Float = Float(index) * step
|
||||
if isShow == true {
|
||||
delegate?.circleMenu?(self, willDisplay: button, atIndex: index)
|
||||
|
||||
let angle: Float = startAngle + Float(index) * step
|
||||
button.rotatedZ(angle: angle, animated: false, delay: Double(index) * showDelay)
|
||||
button.showAnimation(distance: distance, duration: duration, delay: Double(index) * showDelay)
|
||||
} else {
|
||||
@@ -359,14 +410,14 @@ open class CircleMenu: UIButton {
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func tapBounceAnimation() {
|
||||
fileprivate func tapBounceAnimation(duration: TimeInterval, completion: ((Bool)->())? = nil) {
|
||||
transform = CGAffineTransform(scaleX: 0.9, y: 0.9)
|
||||
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.3, initialSpringVelocity: 5,
|
||||
UIView.animate(withDuration: duration, delay: 0, usingSpringWithDamping: 0.3, initialSpringVelocity: 5,
|
||||
options: UIViewAnimationOptions.curveLinear,
|
||||
animations: { () -> Void in
|
||||
self.transform = CGAffineTransform(scaleX: 1, y: 1)
|
||||
},
|
||||
completion: nil)
|
||||
completion: completion)
|
||||
}
|
||||
|
||||
fileprivate func tapRotatedAnimation(_ duration: Float, isSelected: Bool) {
|
||||
|
||||
Reference in New Issue
Block a user