我使用的是由ermalkaleci的Carbonkit的CarbonTabSwipeNavigation,當視圖加載時,視圖控制器正確對齊,然後切換到第二個視圖控制器時,第二個視圖控制器的對齊正確,但是當滾動回到第一個視圖控制器,它對齊錯誤,第二個視圖控制器的一小部分是可見的。嘗試了我能找到的所有東西,但迄今爲止沒有運氣。我使用的是工具欄,但相同的行爲CarbonKit CarbonTabSwipeNavigation,Viewcontrollers未正確對齊
我的當前設置與insertIntoRootViewController插入時:(
class func setupCarbonPages(carbonSwipeTabsItem:CarbonTabSwipeNavigation,tabTitles:[String],totalWidth: CGFloat) -> CarbonTabSwipeNavigation{
// Setup the default style
carbonSwipeTabsItem.toolbar.translucent = false
carbonSwipeTabsItem.setIndicatorColor(AppConfig.BLUECOLOR)
carbonSwipeTabsItem.setNormalColor(AppConfig.BLUECOLOR)
carbonSwipeTabsItem.setSelectedColor(AppConfig.BLUECOLOR, font: UIFont.boldSystemFontOfSize(14))
carbonSwipeTabsItem.setTabExtraWidth(CGFloat(0))
carbonSwipeTabsItem.setNormalColor(AppConfig.BLUECOLOR, font: AppConfig.REGULAR_FONT_16)
carbonSwipeTabsItem.setSelectedColor(AppConfig.BLUECOLOR, font: AppConfig.REGULAR_FONT_16)
// Assign tab width & preload all data
let menuTabItems:UInt = UInt(tabTitles.count)
let tabWidth = (totalWidth/CGFloat(menuTabItems))
for index:UInt in 0 ..< menuTabItems {
carbonSwipeTabsItem.carbonSegmentedControl!.setWidth(tabWidth, forSegmentAtIndex: Int(index))
}
return carbonSwipeTabsItem
}
然後在我的ViewController:
private func setupSwipableTabs(){
let width = self.view.frame.width
carbonTabSwipeNavigation = CarbonTabSwipeNavigation(items: menuTabTitles as [AnyObject], toolBar: self.toolBar,delegate: self)
Helper.setupCarbonPages(carbonTabSwipeNavigation, tabTitles: menuTabTitles, totalWidth: self.view.frame.width).insertIntoRootViewController(self)
Helper.preloadCarbonPages(carbonTabSwipeNavigation, tabs: 2)
}
庫:https://github.com/ermalkaleci/CarbonKit
沒有運氣,函數被調用viewDidLoad中,試圖ViewDidLayoutSubviews而且,沒有運氣:( –
如果您在視圖中工作負載做了,那麼你必須得到屏幕寬度在調度async –
我會嘗試找出一些其他的解決方案 –