我正在尝试实施CAPSPageMenu。不幸的是,我的视图布局有一些问题。
// MARK: - Scroll menu setup
// Initialize view controllers to display and place in array
var controllerArray : [UIViewController] = []
let controller1 : EventsFeedViewController = EventsFeedViewController(nibName: "ViewControllerOne", bundle: nil)
controller1.title = "Test1"
controllerArray.append(controller1)
let controller2 : LocationsFeedViewController = LocationsFeedViewController(nibName: "ViewControllerTwo", bundle: nil)
controller2.title = "Test2"
controllerArray.append(controller2)
// Customize menu (Optional)
let parameters: [CAPSPageMenuOption] = [
.MenuItemSeparatorWidth(0.0),
.UseMenuLikeSegmentedControl(true),
.MenuItemSeparatorPercentageHeight(0.0),
.SelectedMenuItemLabelColor(UIColor(red: 18.0/255.0, green: 150.0/255.0, blue: 225.0/255.0, alpha: 1.0)),
.ScrollMenuBackgroundColor(UIColor.whiteColor()),
.SelectionIndicatorColor(UIColor(red: 18.0/255.0, green: 150.0/255.0, blue: 225.0/255.0, alpha: 1.0))
]
// Initialize page menu with controller array, frame, and optional parameters
pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRectMake(0.0, 0.0, self.view.frame.width, self.view.frame.height), pageMenuOptions: parameters)
// Lastly add page menu as subview of base view controller view
// or use pageMenu controller in you view hierachy as desired
// Optional delegate
pageMenu!.delegate = self
// self.view.addSubview(pageMenu!.view)
self.addChildViewController(pageMenu!)
self.view.addSubview(pageMenu!.view)
pageMenu!.didMoveToParentViewController(self)
有谁知道我做错了什么?
谢谢
答案 0 :(得分:2)
使用两个视图控制器正常工作:
import UIKit
import PageMenu
class ViewController: UIViewController, CAPSPageMenuDelegate {
var aPageMenu : CAPSPageMenu?
override func viewDidLoad() {
super.viewDidLoad()
var controllerArray : [UIViewController] = []
let profileVC = self.storyboard!.instantiateViewControllerWithIdentifier("VC1")
profileVC.title = "VC 1"
controllerArray.append(profileVC)
let scheduleVC = self.storyboard!.instantiateViewControllerWithIdentifier("VC2")
scheduleVC.title = "VC 2"
controllerArray.append(scheduleVC)
let menuParam: [CAPSPageMenuOption] = [
.MenuItemSeparatorWidth(1.0),
.MenuMargin(20.0),
.MenuHeight(40.0),
.UseMenuLikeSegmentedControl(true),
.MenuItemSeparatorRoundEdges(true),
.SelectionIndicatorHeight(2.0),
.MenuItemSeparatorPercentageHeight(0.5)
]
aPageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRectMake(0.0, 64.0, UIScreen.mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.height-64.0), pageMenuOptions: menuParam)
aPageMenu!.delegate = self
self.view.addSubview(aPageMenu!.view)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}