测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布上次发布 | 2017年1月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Aniruddha Das 维护。
提供带有气泡菜单的动画。
1. Target OS: iOS
2. Supported OS Versions: iOS 9.0+
3. Written in: Swift
4. Supports: Swift 3.0
5. IDE: Xcode 8
6. Architectures Supported: armv7, armv7s, arm64
7. Supported devices: iPhone 5s, iPhone6 and above, and all iPads
请确保您具有菜单图标的必要资源。在我这个例子中,我使用了以下资源。
在您的 ViewController.swift
中编写以下内容:
import UIKit
import ADBubbleMenu
class ViewController: UIViewController {
var upMenuView: ADBubbleMenuButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidAppear(_ animated: Bool) {
// Create up menu button
if upMenuView == nil {
let homeLabel2 = self.createHomeButtonView()
upMenuView = ADBubbleMenuButton(frame: CGRect(x: self.view.frame.size.width - homeLabel2.frame.size.width - 30.0, y: self.view.frame.size.height - homeLabel2.frame.size.height - 50.0,
width: homeLabel2.frame.size.width, height: homeLabel2.frame.size.height), expansionDirection: .directionUp)
upMenuView.homeButtonView = homeLabel2
upMenuView.addButtons(self.createDemoButtonArray())
self.view.addSubview(upMenuView)
}
}
func createHomeButtonView() -> UILabel {
let label = UILabel(frame: CGRect(x: 0.0, y: 0.0, width: 40.0, height: 40.0))
label.layer.cornerRadius = label.frame.size.height / 2.0
let button = UIButton(frame: CGRect(x: 0.0, y: 0.0, width: 40.0, height: 40.0))
button.layer.cornerRadius = button.frame.size.height / 2.0
button.setBackgroundImage(UIImage(named: "fab_icon"), for: .normal)
label.addSubview(button)
return label
}
func createDemoButtonArray() -> [UIButton] {
var buttons: [UIButton]=[]
var i = 0
for str in ["help screen_mail_icon", "help screen_call_icon"] {
let button: UIButton = UIButton(type: UIButtonType.custom)
button.setBackgroundImage(UIImage(named: str), for: .normal)
button.frame = CGRect(x: 0.0, y: 0.0, width: 40.0, height: 40.0)
button.contentMode = .scaleAspectFit
button.layer.cornerRadius = button.frame.size.height / 2.0
i += 1
button.tag = i
button.addTarget(self, action: #selector(self.buttonTap(_:)), for: UIControlEvents.touchUpInside)
buttons.append(button)
}
return buttons
}
func buttonTap(_ sender: UIButton) {
switch sender.tag {
case 1:
print("Mail Pressed")
case 2:
print("Call Pressed")
default: break
}
}
}