上拉菜单实质上是和alertview一样的
只不过实在样式的改变方面用的是
UIAlertControllerStyle.ActionSheet这个
具体看代码
class ViewController: UIViewController {
//声明一个UIAlertController实例,以便在下方代码中进行调用
var controller: UIAlertController?
override func viewDidLoad() {
//创建一个alertcontroller的实例 最上面的标题,还有信息,以上拉菜单actionsheet来显示出来
controller = UIAlertController(title: "曹凯强", message: "爱我请点我", preferredStyle: UIAlertControllerStyle.ActionSheet)
//创建在点击的时候该发生什么函数 action 应该创建多个action
// Do any additional setup after loading the view, typically from a nib.
//第一个action
let action1 = UIAlertAction(title: "cao", style: UIAlertActionStyle.Default) { (paramAction:UIAlertAction) -> Void in
}
//第二个action
let action2 = UIAlertAction(title: "cao", style: UIAlertActionStyle.Default) { (paramAction:UIAlertAction) -> Void in
}
//第三个action
let action3 = UIAlertAction(title: "cao", style: UIAlertActionStyle.Destructive) { (paramAction:UIAlertAction) -> Void in
}
//添加多个action
controller?.addAction(action1)
controller?.addAction(action2)
controller?.addAction(action3)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//应该是在主视图加载完成之后再去显示这个视图,所以要重写这个函数
//viewDidAppear
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(true)
//呈现这个controller的时候所用的方法
self.presentViewController(controller!, animated: true, completion: nil)
}
}
要创建多个action 以便于添加