Good afternoon
I want to make a drop down menu animated. I succeed in unhiding the buttons, but can't succeed in make the drop down animation. I'm missing something. Some help please?
When I press botonDropDown, I want all the buttons to drop down.
Here is the code:
import UIKit
extension UIView {
func addBottomBorderWithColor(color: UIColor, width: CGFloat) {
let border = CALayer()
border.backgroundColor = color.cgColor
border.frame = CGRect(x: 0, y: self.frame.size.height - width, width: frame.size.width, height: width)
self.layer.addSublayer(border)
}
func addLeftBorderWithColor(color: UIColor, width: CGFloat) {
let border = CALayer()
border.backgroundColor = color.cgColor
border.frame = CGRect(x: 0, y: 0, width: width, height: self.frame.size.height)
self.layer.addSublayer(border)
}
func addRightBorderWithColor(color: UIColor, width: CGFloat) {
let border = CALayer()
border.backgroundColor = color.cgColor
border.frame = CGRect(x: frame.size.width - width, y: 0, width: width, height: self.frame.size.height)
self.layer.addSublayer(border)
}
func addTopBorderWithColor(color: UIColor, width: CGFloat) {
let border = CALayer()
border.backgroundColor = color.cgColor
border.frame = CGRect(x: 0, y: 0, width: frame.size.width, height: width)
self.layer.addSublayer(border)
}
}
class ViewController: UIViewController {
@IBOutlet weak var botonLong: UIButton!
@IBOutlet weak var botonVolum: UIButton!
@IBOutlet weak var botonMasa: UIButton!
@IBOutlet weak var botonTemp: UIButton!
@IBOutlet weak var botonVeloc: UIButton!
@IBOutlet weak var botonCaudal: UIButton!
@IBOutlet weak var botonPoten: UIButton!
@IBOutlet weak var botonPresion: UIButton!
@IBOutlet weak var botonPropDown: UIButton!
@IBOutlet var measureSelected: [UIButton]! // in this UICollectionView, I have dragg all the buttons from the Main.storyboard
override func viewDidLoad() {
super.viewDidLoad()
botonPropDown.addBottomBorderWithColor(color: UIColor.white, width: 3)
botonLong.addBottomBorderWithColor(color: UIColor.white, width: 1)
botonLong.addRightBorderWithColor(color: UIColor.white, width: 1)
botonVolum.addBottomBorderWithColor(color: UIColor.white, width: 1)
botonVolum.addLeftBorderWithColor(color: UIColor.white, width: 1)
botonVolum.addRightBorderWithColor(color: UIColor.white, width: 1)
botonMasa.addBottomBorderWithColor(color: UIColor.white, width: 1)
botonMasa.addLeftBorderWithColor(color: UIColor.white, width: 1)
botonMasa.addRightBorderWithColor(color: UIColor.white, width: 1)
botonTemp.addBottomBorderWithColor(color: UIColor.white, width: 1)
botonTemp.addLeftBorderWithColor(color: UIColor.white, width: 1)
botonVeloc.addTopBorderWithColor(color: UIColor.white, width: 1)
botonVeloc.addRightBorderWithColor(color: UIColor.white, width: 1)
botonCaudal.addTopBorderWithColor(color: UIColor.white, width: 1)
botonCaudal.addRightBorderWithColor(color: UIColor.white, width: 1)
botonCaudal.addLeftBorderWithColor(color: UIColor.white, width: 1)
botonPoten.addTopBorderWithColor(color: UIColor.white, width: 1)
botonPoten.addLeftBorderWithColor(color: UIColor.white, width: 1)
botonPoten.addRightBorderWithColor(color: UIColor.white, width: 1)
botonPresion.addTopBorderWithColor(color: UIColor.white, width: 1)
botonPresion.addLeftBorderWithColor(color: UIColor.white, width: 1)
}
// in this IBAction I have dragged all buttons from Main.storyboard
@IBAction func propDownPressed(_ sender: UIButton) {
measureSelected.forEach { (button) in UIView.animate(withDuration: 0.3, animations: {
button.isHidden = !button.isHidden
self.view.layoutIfNeeded()
})
}
}
Thanks for the help.