「Ios/swift/外部ライブラリ/DrawerController」の版間の差分
ナビゲーションに移動
検索に移動
編集の要約なし |
編集の要約なし |
||
| 12行目: | 12行目: | ||
==ナビゲーションバー付きドロワーメニューを作成== | ==ナビゲーションバー付きドロワーメニューを作成== | ||
#ViewControllerのStoryboardIDに" | #ViewControllerのStoryboardIDに"CenterNavigationControllerId"を追加 | ||
#以下の通りswiftファイルを編集する | #以下の通りswiftファイルを編集する | ||
#storyboardに新しくViewControllerを追加し、クラス名をDrawerViewControllerとし、StoryboardIDを" | #storyboardに新しくViewControllerを追加し、クラス名をDrawerViewControllerとし、StoryboardIDを"DrawerViewControllerId"にする | ||
-AppDelegate.swift | -AppDelegate.swift | ||
| 24行目: | 24行目: | ||
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { | ||
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()) | let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()) | ||
let centerViewController: ViewController! = storyboard.instantiateViewControllerWithIdentifier(" | let centerViewController: ViewController! = storyboard.instantiateViewControllerWithIdentifier("CenterNavigationControllerId") as! ViewController | ||
let navigationController: UINavigationController! = UINavigationController(rootViewController: centerViewController) | let navigationController: UINavigationController! = UINavigationController(rootViewController: centerViewController) | ||
let drawerViewController: DrawerViewController! = storyboard.instantiateViewControllerWithIdentifier(" | let drawerViewController: DrawerViewController! = storyboard.instantiateViewControllerWithIdentifier("DrawerViewControllerId") as! DrawerViewController | ||
let drawerController: DrawerController! = DrawerController(centerViewController: navigationController, leftDrawerViewController: drawerViewController) | let drawerController: DrawerController! = DrawerController(centerViewController: navigationController, leftDrawerViewController: drawerViewController) | ||
drawerController.showsShadows = true // 影付き | drawerController.showsShadows = true // 影付き | ||
2016年6月26日 (日) 20:15時点における版
公式
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に"CenterNavigationControllerId"を追加
- 以下の通りswiftファイルを編集する
- storyboardに新しくViewControllerを追加し、クラス名をDrawerViewControllerとし、StoryboardIDを"DrawerViewControllerId"にする
-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("CenterNavigationControllerId") as! ViewController
let navigationController: UINavigationController! = UINavigationController(rootViewController: centerViewController)
let drawerViewController: DrawerViewController! = storyboard.instantiateViewControllerWithIdentifier("DrawerViewControllerId") 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のナビゲーションViewを取り込む方法
NavigationControllerのStoryboradIDに"CenterNavigation"を追加し、navigationControllerを以下に差し替える。
let navigationController: UINavigationController! = storyboard.instantiateViewControllerWithIdentifier("CenterNavigation") as! UINavigationController