「Ios/swift/外部ライブラリ/DrawerController」の版間の差分
提供: 初心者エンジニアの簡易メモ
行71: | 行71: | ||
==ボタンはこちらを参考== | ==ボタンはこちらを参考== | ||
[[ios/swift/ButtonSystem]] [ショートカット] | [[ios/swift/ButtonSystem]] [ショートカット] | ||
+ | |||
+ | ==storyboardのナビゲーションを取り込む方法== | ||
+ | NavigationControllerのStoryboradIDに"CenterNavigation"を追加し、navigationControllerを以下に差し替える。 | ||
+ | let navigationController: UINavigationController! = storyboard.instantiateViewControllerWithIdentifier("CenterNavigation") as! UINavigationController | ||
==参考== | ==参考== | ||
*http://engineer-terminal.com/2016/01/09/%E3%82%B9%E3%83%9E%E3%83%9B%E3%82%A2%E3%83%97%E3%83%AA%E3%81%A7%E3%81%AB%E3%81%AF%E6%AC%A0%E3%81%8B%E3%81%9B%E3%81%AA%E3%81%84%E3%81%82%E3%82%8B%E3%82%A2%E3%83%AC%E3%82%92%E4%BD%9C%E3%82%8B-swift/ | *http://engineer-terminal.com/2016/01/09/%E3%82%B9%E3%83%9E%E3%83%9B%E3%82%A2%E3%83%97%E3%83%AA%E3%81%A7%E3%81%AB%E3%81%AF%E6%AC%A0%E3%81%8B%E3%81%9B%E3%81%AA%E3%81%84%E3%81%82%E3%82%8B%E3%82%A2%E3%83%AC%E3%82%92%E4%BD%9C%E3%82%8B-swift/ | ||
*https://teratail.com/questions/25333 | *https://teratail.com/questions/25333 |
2016年6月26日 (日) 11:02時点における版
公式
https://github.com/sascha/DrawerController/
インストール
$ vi Podfile platform :ios, '9.0' target 'HelloworldDrawer' do use_frameworks! pod "DrawerController", '~> 1.0' end $ pod install
ナビゲーションバー付きドロワーメニューを作成
- ViewControllerのStoryboardIDに"Center"を追加
- 以下の通りswiftファイルを編集する
- storyboardに新しくViewControllerを追加し、クラス名をDrawerViewControllerとし、StoryboardIDを"Drawer"にする
-AppDelegate.swift
import UIKit import DrawerController @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()) let centerViewController: ViewController! = storyboard.instantiateViewControllerWithIdentifier("Center") as! ViewController let navigationController: UINavigationController! = UINavigationController(rootViewController: centerViewController) let drawerViewController: DrawerViewController! = storyboard.instantiateViewControllerWithIdentifier("Drawer") as! DrawerViewController let drawerController: DrawerController! = DrawerController(centerViewController: navigationController, leftDrawerViewController: drawerViewController) drawerController.showsShadows = true // 影付き drawerController.restorationIdentifier = "Drawer" drawerController.maximumLeftDrawerWidth = 240.0 // 幅240 drawerController.openDrawerGestureModeMask = .All // タッチ操作を全て受け付ける drawerController.closeDrawerGestureModeMask = .All self.window = UIWindow(frame: UIScreen.mainScreen().bounds) self.window?.rootViewController = drawerController self.window?.makeKeyAndVisible() return true } // 略 }
-ViewController.swift
import UIKit import DrawerController class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = UIColor.blueColor() let btn = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Bookmarks, target: self, action:#selector(ViewController.drawerOnClickButton(_:))) self.navigationItem.setLeftBarButtonItems([btn], animated: true) } // 左メニューを開く func drawerOnClickButton(sender: AnyObject?) { self.evo_drawerController?.toggleDrawerSide(.Left, animated: true, completion: nil) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } }
-DrawerViewController.swift
import UIKit class DrawerViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } }
ボタンはこちらを参考
ios/swift/ButtonSystem [ショートカット]
storyboardのナビゲーションを取り込む方法
NavigationControllerのStoryboradIDに"CenterNavigation"を追加し、navigationControllerを以下に差し替える。
let navigationController: UINavigationController! = storyboard.instantiateViewControllerWithIdentifier("CenterNavigation") as! UINavigationController