Skip to content

Instantly share code, notes, and snippets.

@monmon
Created September 19, 2012 07:35
Show Gist options
  • Select an option

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

Select an option

Save monmon/3748206 to your computer and use it in GitHub Desktop.
NGVaryingGridViewでサンプルコード勉強会

使い方

概要

  • TableViewと同じようにgridViewDelegateを実装してcellを作る
    • @required rectsForCellsInGridView:
      • cellの位置情報を含んだCGRectのNSArrayを作り、それを返す
    • @required gridView:viewForCellWithRect:index:
      • cellに何を表示したいかの情報。自分でcellクラスのviewを作って、そのviewを表示させる
    • @optional gridView:didSelectCell:index:
      • cellをタップされたときのdelegate
    • @optional gridView:willPrepareCellForReuse:
      • cellを再利用する時に何かしたければ
  • NGVaryingGridView自体は一枚のUIView
    • subViewにUIScrollViewを持つことで「スクロールしてcellを表示」を実現
  • setStickyView:lockPosition:を使って「日」や「時間」の帯をtop or leftに貼付ける
  • UIScrollViewのdelegateを実装していて、そのscrollViewDidScrollの中で「cellを表示」「stickyViewのpositionをupdate」「ScrollIndicator(スクロール)を手前に表示」ってのをやっている

メソッドを眺める

  • - (void)reloadData
    • 現在の描画領域に描画
  • - (UIView *)gridCellWithCGPoint:(CGPoint)point;
    • 指定したpointを内包しているgridCellを返す
  • - (void)scrollToGridCell:(UIView *)cell animated:(BOOL)animated
    • 指定したcellの所までscroll。UIScrollView scrollRectToVisible:を内部で呼び出す
  • - (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated
    • 上と似たようなもの
  • - (void)addOverlayView:(UIView *)overlayView
    • overlayViewを被せるようだけど、何のため用だろう??
  • - (UIView *)dequeueReusableCell __attribute__((deprecated))
    • dequeueReusableCellWithFrameを呼んでるだけ。deprecatedの警告の出したいときはこう書く。
  • - (UIView *)dequeueReusableCellWithFrame:(CGRect)frame
    • ScrollIndicatorを手前に表示
  • - (void)setStickyView:(UIView *)view lockPosition:(NGVaryingGridViewLockPosition)lockPosition
    • 「日」や「時間」の帯をtop or leftに貼付け
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment