9

下の画像でわかるように、Twitter は、プッシュされたビュー コントローラーごとに異なるナビゲーション バーの色を使用します。

私はほとんどすべて (setbackgroundimage、backgroundcolor、bartintcolor など) を試しましたが、何も機能していないようです。私が思うに、Twitter はプッシュをシミュレートするためにカスタム トランジションを使用しています。

ここに画像の説明を入力ここに画像の説明を入力

4

4 に答える 4

4

navigationBarさまざまなを処理したい場合はbarTintColorCode Schoolにチュートリアルがありました。( iOS アプリ: カスタム ナビゲーション バーの作成setBackgroundImage:forBarMetrics:)メソッドを使用して、さまざまな背景に拡張することもできます。

次の 4 つの手順があります。

  1. これをviewWillAppearソース ビュー コントローラーで処理し、提供されたnavigationBarを非表示にしnavigationControllerて、 に新しいnavigationBarを作成しますsuperView

    - (void)styleNavBar
    {
        // 1. hide the existing nav bar
        [self.navigationController setNavigationBarHidden:YES animated:NO];
    
        // 2. create a new nav bar and style it
        UINavigationBar *newNavBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 64.0)];
        [newNavBar setTintColor:[UIColor whiteColor]];
    
        // 3. add a new navigation item w/title to the new nav bar
        UINavigationItem *newItem = [[UINavigationItem alloc] init];
        newItem.title = @"Source";
        [newNavBar setItems:@[newItem]];
    
        // 4. add the nav bar to the main view
        [self.view addSubview:newNavBar];
    }
    
  2. viewWillAppear宛先ビュー コントローラーで同じトリックを実行しbackBarButtonItem、新しいものとしてを作成しnavigationBarますleftBarButtonItem

    - (void)styleNavBar 
    {
        [self.navigationController setNavigationBarHidden:YES animated:NO];
        UINavigationBar *newNavBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 64.0)];
        [newNavBar setTintColor:[UIColor blueColor]];
        UINavigationItem *newItem = [[UINavigationItem alloc] init];
        newItem.title = @"Destination";
    
        // BackButtonBlack is an image we created and added to the app’s asset catalog
        UIImage *backButtonImage = [UIImage imageNamed:@"BackButtonBlack"];
    
        // any buttons in a navigation bar are UIBarButtonItems, not just regular UIButtons. backTapped: is the method we’ll call when this button is tapped
        UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:backButtonImage
                                                                              style:UIBarButtonItemStylePlain
                                                                             target:self
                                                                             action:@selector(backTapped:)];
    
        // the bar button item is actually set on the navigation item, not the navigation bar itself.
        newItem.leftBarButtonItem = backBarButtonItem;
    
        [newNavBar setItems:@[newItem]];
        [self.view addSubview:newNavBar];
    }
    
  3. backTapped:ユーザーが目的のビュー コントローラーからタップしてポップオーバーできるように、メソッドに入力します。

    - (void)backTapped:(id)sender
    {
        [self.navigationController popViewControllerAnimated:YES];
    }
    
  4. スワイプしてポップする状況を考慮して、ジェスチャ レコグナイザーのデリゲートを宛先ビュー コントローラーのselfinに設定します。(著者: ここでの解決策はちょっとしたハックです。)viewWillAppear

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        [self styleNavBar];
    
        __weak id weakSelf = self;
        self.navigationController.interactivePopGestureRecognizer.delegate = weakSelf;
    }
    
于 2015-01-03T00:27:43.113 に答える
2

Twitter はナビゲーション バーの色を変更しません。ユーザーのプロフィールを見ると、それはユーザーのカバー写真のぼやけたバージョンです。

遷移でわかるように、ユーザー プロファイル ビュー全体が以前のビューに置き換わります。ナビゲーション バーは変更されず、置き換えられます。UINavigationBar を使用しない場合もあります (または、少なくともナビゲーション コントローラーのバーを使用しない場合もあります)。

「バー」は、ユーザーのカバー写真を表示するカスタム ビューで、戻る/検索/ツイート ボタンが通常の位置に表示されます。下にスクロールすると、ユーザーのカバー写真が縮小し、ぼやけて画面の上部にくっつきます。この時点では、通常のナビゲーション バーのように見えます。この時点で、ユーザーの名前とツイート数もナビゲーション バーの中央までスクロールします。

これは非常に興味をそそるもので、ユーザー プロファイルのビュー全体の構造には、おそらく多くのトリックが使用されています。しかし、彼らのプロフィール ビューを模倣するのは簡単なことではなく、ナビゲーション バーの色合いを変更するだけではありません。これをやりたいだけなら、元に戻すの答えがうまくいきます。viewWillAppearただし、 (古いビューと新しいビューの) メソッドで色合いをリセットする必要がある場合もあります。

于 2014-09-30T23:43:17.867 に答える
0

この GitHub リポジトリを調べてみてください。その効果を達成するのに役立つと思いますhttps://github.com/kingiol/KDInteractiveNavigationController

于 2016-04-21T14:55:39.393 に答える