Ryusuke Fuda's Tech Blog

Softweare Enginier about Web, iOS, Android.

iOS JASidePanelsをstoryboardで実装

nanapiのアンサーなどに使われている、サイドメニューのライブラリJASidePanelsを既存のシステムに追加実装する。

JASidePanels Github
https://github.com/gotosleep/JASidePanels

■ cocoapodsでインストール
Podfile

pod 'JASidePanels'

■ 新しいClassを追加(MySidePanelControllerという名前でやる)
File>New>File>Objective-C Class>
※Subclass of を JASidePanelController にする

■ storyboardで新しいViewControllerを作りCustom Classを"MySidePanelController"にする。
storyboardのRootView(矢印のView)をMySidePanelControllerにする。

■ 左側に出てくるViewをつくる
Storyboardで新しくViewControllerを追加し、SideViewController ClassをつくりCustom Classに設定する。

■ 今あるViewのNavigationControllerにStoryboard IDをつける
TopNavigationController とする。

■ MySidePanelControllerにコードを追加
MySidePanelController.m

-(void) awakeFromNib
{
    //SideViewControllerが左側に出てくるViewのStoryboard ID
    [self setLeftPanel:[self.storyboard instantiateViewControllerWithIdentifier:@"SideViewController"]];
    //TopNavigationControllerが真ん中のViewのStoryboard ID
    [self setCenterPanel:[self.storyboard instantiateViewControllerWithIdentifier:@"TopNavigationController"]];
    //左側のViewの幅も指定できる
    [self setLeftFixedWidth:200];
}

これでビルドすると今までのViewの左上にボタンができて押すとヒュッと左側にSideViewControllerのViewが出る。