facebook twitter hatena line email

「Ios/swift/外部ライブラリ/DrawerController」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ページの作成:「==インストール== $ vi Podfile platform :ios, '9.0' target 'HelloworldDrawer' do use_frameworks! pod "DrawerController", '~> 1.0' end $ pod install ==ナ...」)
(相違点なし)

2016年6月26日 (日) 08:05時点における版

インストール

$ vi Podfile
platform :ios, '9.0'
target 'HelloworldDrawer' do
 use_frameworks!
 pod "DrawerController", '~> 1.0'
end
$ pod install

ナビゲーションバー付きドロワーメニューを作成

  1. ViewControllerのStoryboardIDに"Center"を追加
  2. 以下の通りswiftファイルを編集する
  3. 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()
   }
}