Skip to content

Instantly share code, notes, and snippets.

@monmon
Created July 19, 2012 08:35
Show Gist options
  • Select an option

  • Save monmon/3141604 to your computer and use it in GitHub Desktop.

Select an option

Save monmon/3141604 to your computer and use it in GitHub Desktop.
Sparrowで使われているoverlayのmenuサンプルであるMHTabBarController

http://www.cocoacontrols.com/platforms/ios/controls/qbkoverlaymenuview https://github.com/hollance/MHTabBarController/

大まかな流れ

  • overlay menu機能はQBKOverlayMenuViewで完結
  • QBKRootViewControllerがQBKOverlayMenuViewを保持
  • viewDidLoadの以下の2行でviewにoverlay menuが追加され、表示される _qbkOverlayMenu = [[QBKOverlayMenuView alloc] initWithDelegate:self position:kQBKOverlayMenuViewPositionBottom offset:offset]; [_qbkOverlayMenu setParentView:[self view]];
    • selfを渡しているのはmenuのdelegateを自分が処理したいため
    • setParentViewの中でaddSubViewしていて、その時点で表示
  • その後のaddButtonWithImageでunfold時に表示する画像を追加 [_qbkOverlayMenu addButtonWithImage:[UIImage imageNamed:@"rw-button.png"] index:0];
    • このdemoのソースでは4つが固定なのでそこが微妙かも
      • QBK_OVERLAY_MENU_MAX_ADDITIONAL_BUTTONSで「4」を指定しているけど、addButtonWithImageの前とかに指定したらいいんじゃないのかな

QBKOverlayMenuView.h

  • QBKOverlayMenuViewDelegate Protocolを宣言
    • (void)overlayMenuView:(QBKOverlayMenuView *)overlayMenuView didActivateAdditionalButtonWithIndex:(NSInteger)index;
      • unfold時にボタンがtapされたら呼ばれてtapしたindexが渡されてくる
    • (void)didPerformUnfoldActionInOverlayMenuView:(QBKOverlayMenuView *)overlaymenuView;
      • unflodしたら呼び出される
    • (void)didPerformFoldActionInOverlayMenuView:(QBKOverlayMenuView *)overlaymenuView;
      • flodしたら呼び出される

QBKOverlayMenuView.m

  • - (void)setParentView:(UIView *)view

    1. createFoldedMainFrameForPositionでガムシャラに[_parentView bounds]でrootViewのサイズなどを見ながら表示位置を計算
    2. setClipsToBounds:YESにしてるけどコレは何用だろう?
    3. setupMainButtonメソッドで初期値であるfoldのbuttonを作り、setAutoresizingMask:UIViewAutoresizingFlexibleLeftMarginでfold時もunfold時も常に右端にmainButtonが来るように配置、tap時のactionをmainButtonPressedに設定
      • addSubviewでそのbuttonを追加
    4. _mainBackgroundImageViewにunfold時のbackground imageを作り、addSubviewで追加、sendSubviewToBackでmainButtonより背面へ配置、setAlphaで透明化
    5. 最後にsetupContentViewでfold時のcontentsのviewを作成
  • - (void)setupContentView

    1. createFoldedContentViewFrameForPositionでfoldのcontentsを作成
    2. setClipsToBounds:YESでfoldのcontents(この場合矢印)を非表示(はみ出ているところを非表示)にする
      • これYESだと出なくてNOだと出る意味がわからない。どういう状態になっているんだろ
    3. setAutoresizingMask:UIViewAutoresizingFlexibleWidth
      • これがないと矢印出て来ないけど、初期の位置がどうなっているかわからず
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment