Ios 从情节提要实现页面菜单/初始化视图控制器
我正在努力让这个吊舱在我的项目中工作,我一直在理解这个吊舱是如何工作的: 我见过一些东西说我需要用我在情节提要中设置的情节提要ID初始化视图控制器,但是当我尝试做类似的事情时Ios 从情节提要实现页面菜单/初始化视图控制器,ios,swift,uiviewcontroller,uistoryboard,Ios,Swift,Uiviewcontroller,Uistoryboard,我正在努力让这个吊舱在我的项目中工作,我一直在理解这个吊舱是如何工作的: 我见过一些东西说我需要用我在情节提要中设置的情节提要ID初始化视图控制器,但是当我尝试做类似的事情时 let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil) let vc = storyboard.instantiateViewControllerWithIdentifier("someViewController") as! UI
let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("someViewController") as! UIViewController
self.presentViewController(vc, animated: true, completion: nil)
但老实说,我不知道该放在哪里/什么时候放/如果那是什么
我们的想法是为页面菜单创建一个视图控制器数组,并在顶部显示选项卡栏,但我不确定如何从我在故事板中创建的视图中创建该数组 给你。PageMenu超级酷,超级可定制。玩得高兴希望这有帮助。如果您遇到任何其他问题,请告诉我
var pageMenu: CAPSPageMenu?
override func viewDidLoad() {
super.viewDidLoad()
setupPages()
}
func setupPages() {
var controllerArray: [UIViewController] = []
let firstVC = FirstViewController()
firstVC.title = "FirstOne"
let secondVC = SecondViewController()
secondVC.title = "Another One"
let thirdVC = ThirdViewController()
thirdVC.title = "And Another One"
controllerArray.append(firstVC)
controllerArray.append(secondVC)
controllerArray.append(thirdVC)
// a bunch of random customization
let parameters: [CAPSPageMenuOption] = [
.ScrollMenuBackgroundColor(UIColor.quotesBackgroundColor()),
.ViewBackgroundColor(UIColor.quotesBackgroundColor()),
.SelectionIndicatorColor(UIColor.peterRiverColor()),
.BottomMenuHairlineColor(UIColor(red: 70.0/255.0, green: 70.0/255.0, blue: 80.0/255.0, alpha: 1.0)),
.MenuHeight(40.0),
.MenuItemWidth(100.0),
.CenterMenuItems(true),
.SelectedMenuItemLabelColor(UIColor.blueColor())
]
pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRectMake(0.0, 0.0, self.view.frame.width, self.view.frame.height), pageMenuOptions: parameters)
self.view.addSubview(pageMenu!.view)
}
给你。PageMenu超级酷,超级可定制。玩得高兴希望这有帮助。如果您遇到任何其他问题,请告诉我
var pageMenu: CAPSPageMenu?
override func viewDidLoad() {
super.viewDidLoad()
setupPages()
}
func setupPages() {
var controllerArray: [UIViewController] = []
let firstVC = FirstViewController()
firstVC.title = "FirstOne"
let secondVC = SecondViewController()
secondVC.title = "Another One"
let thirdVC = ThirdViewController()
thirdVC.title = "And Another One"
controllerArray.append(firstVC)
controllerArray.append(secondVC)
controllerArray.append(thirdVC)
// a bunch of random customization
let parameters: [CAPSPageMenuOption] = [
.ScrollMenuBackgroundColor(UIColor.quotesBackgroundColor()),
.ViewBackgroundColor(UIColor.quotesBackgroundColor()),
.SelectionIndicatorColor(UIColor.peterRiverColor()),
.BottomMenuHairlineColor(UIColor(red: 70.0/255.0, green: 70.0/255.0, blue: 80.0/255.0, alpha: 1.0)),
.MenuHeight(40.0),
.MenuItemWidth(100.0),
.CenterMenuItems(true),
.SelectedMenuItemLabelColor(UIColor.blueColor())
]
pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRectMake(0.0, 0.0, self.view.frame.width, self.view.frame.height), pageMenuOptions: parameters)
self.view.addSubview(pageMenu!.view)
}
如果您使用故事板ID进行viewcontroller实例化,请修改上述答案
var pageMenu: CAPSPageMenu?
override func viewDidLoad() {
super.viewDidLoad()
setupPages()
}
func setupPages() {
let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
var controllerArray: [UIViewController] = []
let firstVC = storyboard.instantiateViewControllerWithIdentifier("FirstViewControlleridentifier") as! FirstViewController
firstVC.title = "FirstOne"
let secondVC = storyboard.instantiateViewControllerWithIdentifier("SecondViewControlleridentifier") as! SecondViewController
secondVC.title = "Another One"
let thirdVC = storyboard.instantiateViewControllerWithIdentifier("ThirdViewControlleridentifier") as! ThirdViewController
thirdVC.title = "And Another One"
controllerArray.append(firstVC)
controllerArray.append(secondVC)
controllerArray.append(thirdVC)
// a bunch of random customization
let parameters: [CAPSPageMenuOption] = [
.ScrollMenuBackgroundColor(UIColor.quotesBackgroundColor()),
.ViewBackgroundColor(UIColor.quotesBackgroundColor()),
.SelectionIndicatorColor(UIColor.peterRiverColor()),
.BottomMenuHairlineColor(UIColor(red: 70.0/255.0, green: 70.0/255.0, blue: 80.0/255.0, alpha: 1.0)),
.MenuHeight(40.0),
.MenuItemWidth(100.0),
.CenterMenuItems(true),
.SelectedMenuItemLabelColor(UIColor.blueColor())
]
pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRectMake(0.0, 0.0, self.view.frame.width, self.view.frame.height), pageMenuOptions: parameters)
self.view.addSubview(pageMenu!.view)
}
如果您使用故事板ID进行viewcontroller实例化,请修改上述答案
var pageMenu: CAPSPageMenu?
override func viewDidLoad() {
super.viewDidLoad()
setupPages()
}
func setupPages() {
let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
var controllerArray: [UIViewController] = []
let firstVC = storyboard.instantiateViewControllerWithIdentifier("FirstViewControlleridentifier") as! FirstViewController
firstVC.title = "FirstOne"
let secondVC = storyboard.instantiateViewControllerWithIdentifier("SecondViewControlleridentifier") as! SecondViewController
secondVC.title = "Another One"
let thirdVC = storyboard.instantiateViewControllerWithIdentifier("ThirdViewControlleridentifier") as! ThirdViewController
thirdVC.title = "And Another One"
controllerArray.append(firstVC)
controllerArray.append(secondVC)
controllerArray.append(thirdVC)
// a bunch of random customization
let parameters: [CAPSPageMenuOption] = [
.ScrollMenuBackgroundColor(UIColor.quotesBackgroundColor()),
.ViewBackgroundColor(UIColor.quotesBackgroundColor()),
.SelectionIndicatorColor(UIColor.peterRiverColor()),
.BottomMenuHairlineColor(UIColor(red: 70.0/255.0, green: 70.0/255.0, blue: 80.0/255.0, alpha: 1.0)),
.MenuHeight(40.0),
.MenuItemWidth(100.0),
.CenterMenuItems(true),
.SelectedMenuItemLabelColor(UIColor.blueColor())
]
pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRectMake(0.0, 0.0, self.view.frame.width, self.view.frame.height), pageMenuOptions: parameters)
self.view.addSubview(pageMenu!.view)
}
或者你也可以使用这个回购协议。对于RnD来说,它非常简单,也很容易理解。Swift 3代码
或者你也可以使用这个回购协议。对于RnD来说,它非常简单,也很容易理解。Swift 3代码
更新了David的Swift-3版本 Swift-3的播客文件 pod'页面菜单',:git=>
更新了David的Swift-3版本 Swift-3的播客文件 pod'页面菜单',:git=>
Shrawn的更新Swift-3版本 与iPhone-X模拟器兼容
func setupPages() {
var controllerArray: [UIViewController] = []
let firstVC = FirstVC()
firstVC.title = "First"
let secondVC = SecondVC()
secondVC.title = "Second"
let thirdVC = ThirdVC()
thirdVC.title = "Third"
controllerArray.append(firstVC)
controllerArray.append(secondVC)
controllerArray.append(thirdVC)
let parameters: [CAPSPageMenuOption] = [
.scrollMenuBackgroundColor(.blue),
.viewBackgroundColor(.white),
.selectionIndicatorColor(.white),
.bottomMenuHairlineColor(.white),
.menuHeight(40.0),
.menuItemWidth(self.view.frame.width/3),
.centerMenuItems(true),
.selectedMenuItemLabelColor(.white),
.unselectedMenuItemLabelColor(.white),
.menuMargin(0.0)
]
pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRect(x:0,y:(self.navigationController?.navigationBar.frame.maxY)!,width:self.view.frame.width ,height:self.view.frame.height), pageMenuOptions: parameters)
self.view.addSubview(pageMenu!.view)}
Shrawn的更新Swift-3版本 与iPhone-X模拟器兼容
func setupPages() {
var controllerArray: [UIViewController] = []
let firstVC = FirstVC()
firstVC.title = "First"
let secondVC = SecondVC()
secondVC.title = "Second"
let thirdVC = ThirdVC()
thirdVC.title = "Third"
controllerArray.append(firstVC)
controllerArray.append(secondVC)
controllerArray.append(thirdVC)
let parameters: [CAPSPageMenuOption] = [
.scrollMenuBackgroundColor(.blue),
.viewBackgroundColor(.white),
.selectionIndicatorColor(.white),
.bottomMenuHairlineColor(.white),
.menuHeight(40.0),
.menuItemWidth(self.view.frame.width/3),
.centerMenuItems(true),
.selectedMenuItemLabelColor(.white),
.unselectedMenuItemLabelColor(.white),
.menuMargin(0.0)
]
pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRect(x:0,y:(self.navigationController?.navigationBar.frame.maxY)!,width:self.view.frame.width ,height:self.view.frame.height), pageMenuOptions: parameters)
self.view.addSubview(pageMenu!.view)}
您好,我面临一个问题。如果我从这个基于页面菜单的视图控制器打开gallery,如果我返回,则页面菜单不会出现。您好,我面临一个问题。如果我从此基于页面菜单的视图控制器打开图库,并且如果我返回,则页面菜单将不显示。hii@Aks我面临一个问题…当我尝试在按钮上转到子视图控制器时,单击添加到页面菜单的视图控制器需要时间帮助我,请发布完整信息。将无法帮助处理此小而不清楚的信息。假设我有一个带有两个ViewController的pagemenu选项卡。。。。在其中一个视图控制器中,它们是一个按钮,因此当我单击该按钮时,我将导航到子视图控制器,但子视图需要更多的时间来加载什么问题您可以帮助提供一个示例项目或您尝试过的代码。无法进行私人聊天,抱歉。DispatchQueue.main.async{let findLocation=self.storyboard?.instanceeviewcontrollerwhidentifier:FindViewController as!FindViewController findLocation.LocationFindSingelDict=self.resultingedict findLocation.parentNavigationController=self.navigationController self.parentNavigationController?.pushViewControllerfindLocation,已设置动画:true}这是我尝试过的,它正在导航,但需要时间hii@Aks我面临一个问题…当我试图从添加到页面菜单的ViewController上的按钮单击转到子视图控制器时,需要时间帮助我。请发布完整信息。将无法帮助处理此小而不清楚的信息。假设我有一个页面菜单tab有两个视图控制器…其中一个视图控制器中有一个按钮,因此当我单击该按钮时,我将导航到子视图控制器,但子视图需要更多的时间来加载什么问题您可以提供一个示例项目或您尝试过的内容的代码。无法进行私人聊天,抱歉。DispatchQueue.main.async{let findLocation=self.storyboard?.instanceeviewcontrollerwhidentifier:FindViewController as!FindViewController findLocation.LocationFindSingelDict=self.resultingedict findLocation.parentNavigationController=self.navigationController self.parentNavigationController?.pushViewControllerfindLocation,已设置动画:true}这是我尝试过的导航,但需要时间HII@Nichole H我面临一个问题…当我尝试从添加到页面菜单的ViewController中的按钮单击转到子视图控制器时,需要时间帮助我解决此问题HII@Nichole H我面临一个问题…当我尝试从ViewContro中的按钮单击转到子视图控制器时添加到页面菜单的ller需要时间帮助我您的库需要更新。工作不正常。请检查。您的库需要更新。工作不正常。请检查。