在IOS中使用Floaty创建浮动操作按钮(FAB)



我创建了一个浮动操作按钮,如图所示[https://i.stack.imgur.com/mKUdr.png]在swift中使用floaty。重点是我想通过单击加号按钮导航到另一个视图控制器。我可以通过下面的代码来完成,但我想知道是否有办法在点击加号按钮时直接导航到另一个视图控制器。如果有办法的话,请支持我。谢谢。

func loadFAB(){
let image = UIImage(named: "add")
let floaty = Floaty()

floaty.buttonColor = color
floaty.plusColor = UIColor.white

floaty.addItem(icon: image, handler:{ item in

//navigate to another page
self.performSegue(withIdentifier: "idnewPageSegue", sender: self)})
}

您可以像下面的一样使用

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "nextView") as! NextViewController
self.present(nextViewController, animated:true, completion:nil)
floatyView.addItem(title: "Next"){ item in

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "NextViewController") as! NextViewController
self.present(nextViewController, animated:true, completion:nil)

}
self.view.addSubview(floatyView)

最新更新