4

アプリを作成していて、ナビゲーション ビューの 1 つで、App Store アプリと非常によく似たデザインを使用しています。詳細 | を参照してください。レビュー | 関連セクション。同様の行に従って、Apple がアプリで行った「同じ」方法でセグメント化されたコントロールを実装したいと考えています。(これは、Apple がデフォルトの iOS 7 音楽アプリの [アーティスト] -> [アルバム] ナビゲーション ビューで行っていることと似ていますが、テーブル ヘッダーについては (おそらく))。

  • 上にスクロールすると、セグメント化されたコントロール コンテナーがナビゲーション バーに触れると、そこに固定されます。
  • また、ユーザーは、関連付けられたアルファにより、これがある種のオーバーレイであることを認識できます。
  • 下にスクロールすると、必要な位置に移動します。

私がしたこと —</p>

セグメント化されたコントロールを含むコンテナー ビューを作成しました。scrollView がスクロールしたら、コンテナ ビューの位置を変更して、スティッキー効果を実現します。これは単なる擬似コードですが、私のコードは実際に機能します。

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView == self.labTestScrollView)
    {
        /*
         As soon as the user scrolls up, y changes, therefore, we need to stick the options container view
         such that it doesn't go past the UINavigationBar
         Need to check if the origin of the options container view in the coordinate system of the main
         superview is just gone past the UINavigationBar in this controller's view.
         - get the bounds rect for the options container view
         - convert these bounds and position them in the coordinates of this controller's view
         - check if origin.x for container view is less than that of view.origin.y
         - if less than stick it by converting the headerFrame to the coordinate system of the options 
         container view; and raise the stuck flag
         - if greater, check if the stuck flag is raised; check for another object in space before the container view and adjust accordingly.
         */
    }
}

2 つの問題があります。

  1. オーバーレイ効果なし。効果がもう少し目立つようにアルファを設定できますが、それは自然に見えません。
  2. 2 番目の懸念は、最初の懸念に由来します。これは非常に具体的な解決策のようです。もっと自然な何かを楽しみにしています。テーブルビューなどを使用してデフォルトで機能する可能性のあるもの。
4

2 に答える 2

10

単に使用しないのはなぜUITableViewですか?

「トップ コンテンツ」をセクション 0 に配置し、そのセクションのヘッダーはありません。他のすべてのものをセクション 1 に入れ、そのセクションにUISegmentedControl.

次のコードはかなりうまく機能します。Apple の動作をもう少し模倣するために、ヘッダーの背景に「ぼかし」効果を与える方法を見つけたいと思うかもしれません。多分GPUimageがあなたを助けることができますか?

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return section == 0 ? 1 : 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *identifier = indexPath.section == 0 ? @"header" : @"content";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    // customize cell
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if(section == 1) {
        UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"Foo", @"Bar"]];
        segmentedControl.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.95];
        return segmentedControl;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return section == 0 ? 0 : 44;
}

微調整はお任せします ;)

于 2013-10-08T20:59:45.593 に答える