【问题标题】:Implementing PageMenu / initializing view controllers from storyboard从情节提要实现 PageMenu / 初始化视图控制器
【发布时间】:2016-09-06 02:45:50
【问题描述】:

我正试图让这个 pod 在我的项目中工作,但我一直在理解这个位是如何工作的:

https://github.com/uacaps/PageMenu

// Create variables for all view controllers you want to put in the 
// page menu, initialize them, and add each to the controller array. 
// (Can be any UIViewController subclass)
// Make sure the title property of all view controllers is set
// Example:
var controller : UIViewController = UIViewController(nibName: "controllerNibName", bundle: nil)
controller.title = "SAMPLE TITLE"
controllerArray.append(controller)

我看到一些事情说我需要使用我在故事板中设置的故事板 ID 来初始化视图控制器,但是当我尝试做类似的事情时

let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
let vc =      storyboard.instantiateViewControllerWithIdentifier("someViewController") as! UIViewController
self.presentViewController(vc, animated: true, completion: nil)

但老实说,我不知道该放在哪里/何时放置/如果那甚至是什么

这个想法是为页面菜单制作一组视图控制器,以在顶部显示标签栏,但我不确定如何从我在情节提要中制作的视图中准确制作该数组。

【问题讨论】:

  • hii @Nichole 我正面临一个问题......当我试图从添加到 PageMenu 的 ViewController 按钮单击按钮转到子视图控制器时,需要时间来帮助我解决这个问题

标签: ios swift uiviewcontroller uistoryboard


【解决方案1】:

如果您使用 storyboardIds 进行视图控制器实例化,请修改上述答案。

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)

}

【讨论】:

  • hii @Aks 我面临一个问题......当我试图从添加到 PageMenu 的 ViewController 按钮单击按钮转到子视图控制器时,需要时间来帮助我
  • 请发布完整信息。无法为这些小而不清楚的信息提供帮助。
  • 假设我有一个带有两个视图控制器的页面菜单选项卡......在其中一个视图控制器中,它们是一个按钮,所以当我点击该按钮时,我正在导航到子视图控制器,但子视图需要更多时间加载你可以帮助什么问题
  • 请提供您尝试过的示例项目或代码。无法进行私人聊天,抱歉。
  • DispatchQueue.main.async { 让 findLocation = self.storyboard?.instantiateViewController(withIdentifier: "FindViewController") 作为! FindViewController findLocation.LocationFindSingelDict = self.ResultSingelDict findLocation.parentNavigationController = self.navigationController self.parentNavigationController?.pushViewController(findLocation, animated: true) } 这是我尝试过的导航,但需要时间
【解决方案2】:

更新了 David

的 Swift-3 版本

Swift-3 的 Podfile
pod 'PageMenu' , :git => 'https://github.com/orazz/PageMenu'

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:64,width:self.view.frame.width ,height:self.view.frame.height) , pageMenuOptions: parameters)
     self.view.addSubview(pageMenu!.view)
}

【讨论】:

  • 嗨,我面临一个问题。如果我从这个基于页面菜单的视图控制器打开画廊,如果我回来,那么页面菜单不会出现。
【解决方案3】:

给你。 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)

}

【讨论】:

    【解决方案4】:

    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)}
    

    【讨论】:

      【解决方案5】:

      或者你可以使用这个 repo。它对于 RnD 来说非常简单易懂。 (Swift 3 代码)

      https://github.com/lakshikabhardwaj/LBViewControllerCollection

        let mainViewController = CPPageMenuVC(nibName: "CPPageMenuVC", bundle: nil)
        let pageMenuarray :[PageModal] = [PageModal(pageTitle: "Cat", pageVC: cpCatVC),PageModal(pageTitle: "Cow", pageVC: cowCX),PageModal(pageTitle: "Chat", pageVC: cpCatVC),PageModal(pageTitle: "ElephantElephant", pageVC: elephantVC)]
      
        pageMenuVC.pageArray = pageMenuarray
      

      【讨论】:

      • 您的图书馆需要更新。不能正常工作。请检查。
      猜你喜欢
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-08
      • 2013-05-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多