需求說明
1、啟動APP時悼枢,首頁默認為熱門埠忘;
2、用戶可以左右滑動選擇頻道
3馒索、點擊啦字可以快速定位到熱門最頂部并刷新莹妒;
4、支持下拉刷新
5绰上、單標簽不顯示數字旨怠,多標簽時顯示數字;
工具箱
1蜈块、工具箱跟隨底部欄收起和顯示鉴腻;
2、初始默認顯示出來
需求地址
http://192.168.1.75/114la/220/114la_220/#g=1&p=2_0_%E9%A6%96%E9%A1%B5_%E7%83%AD%E9%97%A8
層次結構
首頁由NewHomePageViewController管理百揭,熱門爽哎、經驗、說明書信峻、我的等需要顯示的則加到其子控制器中倦青,并把view加入其子view。
var encyclopediaVc: LifeEncyclopediaViewController! //熱門
var experienceVc: ExperienceViewController! //經驗
var instructionsVc: InstructionsViewController! //說明書
var meVc: MeViewController! //我的
//各自界面的邏輯由各自界面的字控制器實現及控制盹舞。
新需求中加入了“城市黃頁”产镐,該模塊需要由服務端接口控制是否顯示。
核心代碼
viewdidload時將服務端獲取的是否顯示取出踢步,確保不會被中途修改該字段癣亚。然后使用shouldShowCity屬性作為判斷是否顯示城市黃頁。
shouldShowCity = shouldShowCityPage
將需要顯示的控制器加入首頁的子控制器中,并設置布局获印。
func setupSubController() {
encyclopediaVc = LifeEncyclopediaViewController()
addChildViewController(encyclopediaVc)
encyclopediaVc.didMove(toParentViewController: self)
experienceVc = ExperienceViewController()
addChildViewController(experienceVc)
experienceVc.didMove(toParentViewController: self)
if shouldShowCity {
instructionsVc = InstructionsViewController()
addChildViewController(instructionsVc)
instructionsVc.didMove(toParentViewController: self)
}
meVc = MeViewController()
meVc.shouldHiddenNavBar = true
addChildViewController(meVc)
meVc.didMove(toParentViewController: self)
}
切換到指定的某個界面述雾,添加子控制器的順序與添加子view的順序一致,偏移量根據index計算兼丰。
showVc:指定控制器玻孟。
func showTargetView(showVc: UIViewController, animated: Bool) {
contentCurrentPage = indexForVc(Vc: showVc)
contentScrollView.setContentOffset(CGPoint(x: contentCurrentPage * contentScrollView.frame.width, y: 0), animated: animated)
}
func indexForVc(Vc: UIViewController) -> CGFloat {
return CGFloat(self.childViewControllers.index(of: Vc) ?? 0)
}
func resetHomePage() {
encyclopediaNavBar.hotBtnClicked(encyclopediaNavBar.hotBtn)
encyclopediaVc.scrollToTopAndRefresh()
}
該方法是切換到熱門列表,然后再刷新數據鳍征。