Ios/swift/外部ライブラリ/PagingMenuController
提供: 初心者エンジニアの簡易メモ
PagingMenuControllerとは
smartnewsのようなPageView付きタブを追加してくれるライブラリ
注意:素早く複数回PageView切り替えのスワイプをすると反応しない(一回目のアニメーションが終わるまで反応しない)致命的な欠点がある。結構きになるので、あまりオススメしない。
github:https://github.com/kitasuke/PagingMenuController
podfile例
$ vi podfile source 'https://github.com/CocoaPods/Specs.git' platform :ios, '9.0' target 'Sample1' do use_frameworks! pod 'PagingMenuController' end $ pod install
サンプル
ViewControllerを複数読み込んでます。予めStroyboadのViewControllerのStoryboard_Idに"FirstViewControllerId"を設定してます。
import UIKit import PagingMenuController class PagenewViewController: UIViewController { private var genre_ids: [Int] = [0, 999, 1, 2, 4, 5, 6, 99] private var genre_names: [String] = ["全体", "ランキング", "News", "芸能", "スポーツ", "アニメ", "ゲーム", "その他"] override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) struct MenuItem: MenuItemViewCustomizable { var displayMode: MenuItemDisplayMode { let title = MenuItemText(text: name) return .Text(title: title) } var name = ""; } struct MenuOptions: MenuViewCustomizable { var itemsOptions: [MenuItemViewCustomizable] { var menuItems: Array<MenuItemViewCustomizable> = [] for genre_name in genre_names { let item:MenuItemViewCustomizable = MenuItem(name: genre_name) menuItems.append(item) } return menuItems } var menuDisplayMode: MenuDisplayMode { return .SegmentedControl // return .Standard(widthMode: .Flexible, centerItem: true, scrollingMode: .PagingEnabled) } var genre_names: [String] = [] } struct PagingMenuOptions: PagingMenuControllerCustomizable { var componentType: ComponentType { let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()) var viewControllers: Array<ViewController> = [] var key = 0 for genre_name: String in genre_names { let viewController1 = storyboard.instantiateViewControllerWithIdentifier("FirstViewControllerId") as! ViewController // viewController1.setGenreId(genre_ids[key]) // viewController1.setGenreName(genre_name) viewController1.title = genre_name viewControllers.append(viewController1) key += 1 } return .All(menuOptions: MenuOptions(genre_names:self.genre_names), pagingControllers: viewControllers) } var lazyLoadingPage: LazyLoadingPage { return .Three } var genre_ids: [Int] = [] var genre_names: [String] = [] } let options = PagingMenuOptions(genre_ids:self.genre_ids, genre_names:self.genre_names) let pagingMenuController = PagingMenuController(options: options) addChildViewController(pagingMenuController) view.addSubview(pagingMenuController.view) pagingMenuController.didMoveToParentViewController(self) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } }