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

Updated to iOS 12 and Swift 4.2 #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
30 changes: 15 additions & 15 deletions Source/ActionButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ open class ActionButton: NSObject {
self.floatButton.layer.shadowRadius = 2
self.floatButton.layer.shadowOffset = CGSize(width: 1, height: 1)
self.floatButton.layer.shadowColor = UIColor.gray.cgColor
self.floatButton.setTitle("+", for: UIControlState())
self.floatButton.setImage(nil, for: UIControlState())
self.floatButton.setTitle("+", for: UIControl.State())
self.floatButton.setImage(nil, for: UIControl.State())
self.floatButton.backgroundColor = self.backgroundColor
self.floatButton.titleLabel!.font = UIFont(name: "HelveticaNeue-Light", size: 35)
self.floatButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 8, right: 0)
Expand All @@ -117,13 +117,13 @@ open class ActionButton: NSObject {
}

//MARK: - Set Methods
open func setTitle(_ title: String?, forState state: UIControlState) {
open func setTitle(_ title: String?, forState state: UIControl.State) {
floatButton.setImage(nil, for: state)
floatButton.setTitle(title, for: state)
floatButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 8, right: 0)
}

open func setImage(_ image: UIImage?, forState state: UIControlState) {
open func setImage(_ image: UIImage?, forState state: UIControl.State) {
setTitle(nil, forState: state)
floatButton.setImage(image, for: state)
floatButton.adjustsImageWhenHighlighted = false
Expand All @@ -136,32 +136,32 @@ open class ActionButton: NSObject {
*/
fileprivate func installConstraints() {
let views: [String: UIView] = ["floatButton":self.floatButton, "parentView":self.parentView]
let width = NSLayoutConstraint.constraints(withVisualFormat: "H:[floatButton(\(floatButtonRadius))]", options: NSLayoutFormatOptions.alignAllCenterX, metrics: nil, views: views)
let height = NSLayoutConstraint.constraints(withVisualFormat: "V:[floatButton(\(floatButtonRadius))]", options: NSLayoutFormatOptions.alignAllCenterX, metrics: nil, views: views)
let width = NSLayoutConstraint.constraints(withVisualFormat: "H:[floatButton(\(floatButtonRadius))]", options: NSLayoutConstraint.FormatOptions.alignAllCenterX, metrics: nil, views: views)
let height = NSLayoutConstraint.constraints(withVisualFormat: "V:[floatButton(\(floatButtonRadius))]", options: NSLayoutConstraint.FormatOptions.alignAllCenterX, metrics: nil, views: views)
self.floatButton.addConstraints(width)
self.floatButton.addConstraints(height)

let trailingSpacing = NSLayoutConstraint.constraints(withVisualFormat: "V:[floatButton]-15-|", options: NSLayoutFormatOptions.alignAllCenterX, metrics: nil, views: views)
let bottomSpacing = NSLayoutConstraint.constraints(withVisualFormat: "H:[floatButton]-15-|", options: NSLayoutFormatOptions.alignAllCenterX, metrics: nil, views: views)
let trailingSpacing = NSLayoutConstraint.constraints(withVisualFormat: "V:[floatButton]-15-|", options: NSLayoutConstraint.FormatOptions.alignAllCenterX, metrics: nil, views: views)
let bottomSpacing = NSLayoutConstraint.constraints(withVisualFormat: "H:[floatButton]-15-|", options: NSLayoutConstraint.FormatOptions.alignAllCenterX, metrics: nil, views: views)
self.parentView.addConstraints(trailingSpacing)
self.parentView.addConstraints(bottomSpacing)
}

//MARK: - Button Actions Methods
func buttonTapped(_ sender: UIControl) {
@objc func buttonTapped(_ sender: UIControl) {
animatePressingWithScale(1.0)

if let unwrappedAction = self.action {
unwrappedAction(self)
}
}

func buttonTouchDown(_ sender: UIButton) {
@objc func buttonTouchDown(_ sender: UIButton) {
animatePressingWithScale(0.9)
}

//MARK: - Gesture Recognizer Methods
func backgroundTapped(_ gesture: UIGestureRecognizer) {
@objc func backgroundTapped(_ gesture: UIGestureRecognizer) {
if self.active {
self.toggle()
}
Expand Down Expand Up @@ -205,12 +205,12 @@ open class ActionButton: NSObject {
}

fileprivate func animateMenu() {
let rotation = self.active ? 0 : CGFloat(M_PI_4)
let rotation = self.active ? 0 : Double.pi / 4

UIView.animate(withDuration: 0.3, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.1, options: UIViewAnimationOptions.allowAnimatedContent, animations: {
UIView.animate(withDuration: 0.3, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.1, options: UIView.AnimationOptions.allowAnimatedContent, animations: {

if self.floatButton.imageView?.image == nil {
self.floatButton.transform = CGAffineTransform(rotationAngle: rotation)
self.floatButton.transform = CGAffineTransform(rotationAngle: CGFloat(rotation))
}

self.showActive(false)
Expand Down Expand Up @@ -259,7 +259,7 @@ open class ActionButton: NSObject {
- parameter scale: how much the button should be scaled
*/
fileprivate func animatePressingWithScale(_ scale: CGFloat) {
UIView.animate(withDuration: 0.2, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.1, options: UIViewAnimationOptions.allowAnimatedContent, animations: {
UIView.animate(withDuration: 0.2, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.1, options: UIView.AnimationOptions.allowAnimatedContent, animations: {
self.floatButton.transform = CGAffineTransform(scaleX: scale, y: scale)
}, completion: nil)
}
Expand Down
6 changes: 3 additions & 3 deletions Source/ActionButtonItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ open class ActionButtonItem: NSObject {
self.button.addTarget(self, action: #selector(ActionButtonItem.buttonPressed(_:)), for: .touchUpInside)

if let unwrappedImage = image {
self.button.setImage(unwrappedImage, for: UIControlState())
self.button.setImage(unwrappedImage, for: UIControl.State())
}

if let text = optionalTitle , text.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty == false {
Expand Down Expand Up @@ -126,14 +126,14 @@ open class ActionButtonItem: NSObject {
}

//MARK: - Button Action Methods
func buttonPressed(_ sender: UIButton) {
@objc func buttonPressed(_ sender: UIButton) {
if let unwrappedAction = self.action {
unwrappedAction(self)
}
}

//MARK: - Gesture Recognizer Methods
func labelTapped(_ gesture: UIGestureRecognizer) {
@objc func labelTapped(_ gesture: UIGestureRecognizer) {
if let unwrappedAction = self.action {
unwrappedAction(self)
}
Expand Down