0
我想實現一個CAPSPageMenu。不幸的是,我的視圖佈局存在一些問題。CAPSPageMenu Autolayout
// 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)
有沒有人知道我做錯了什麼?
謝謝
嘿感謝您的回答。代碼與我的基本相同。但我使用.xib文件並且沒有故事板。我認爲問題是,我的VC1和VC2的寬度= 600.000000 height = 600.000000。所以「self.view.frame.width」輸出600我認爲。但我不知道爲什麼。 – Moritz
@Moritz好吧,然後只是測試更新的代碼。通過'UIScreen.mainScreen()獲取屏幕寬度。bounds.size.width' –
結果看起來像這樣。它只是屏幕尺寸的1/3 ... http://i.stack.imgur.com/LcPjS.png – Moritz