2017-10-05 8 views
5

を置き忘れ。iOSの11ナビゲーションTitleViewは私がカスタムナビゲーションのタイトルビューを設定していたにiOSアプリを持っている

これはiOSの10まで細かい仕事をしていたが、iOSの11にナビゲーションタイトルビューは見当違いです。あなたが見ることができるように

The title view is shifted down

からここ

The title view looks fine

iOS版11のためのスクリーンショットである -

ここでは、iOS 10用のスクリーンショットですiOS 10でコードを実行すると、タイトル表示が正常に表示されるというスクリーンショットがあります。しかし、iOS 11の同じコードは、タイトルビューをいくつかのピクセルだけ下にシフトさせ、それはカットされます。

これは私がタイトルビューを設定しています方法です -

navigationItem.titleView = MY_CUSTOM_TITLE_VIEW

私は多くのことを試してみましたが、多くのソリューションを探したが、何も作業していません。

+0

[iOS 11 navigationItem.titleView Width Not Set]の複製が可能です(https://stackoverflow.com/questions/44932084/ios-11-navigationitem-titleview-width-not-set) – Dania

答えて

13

は、それが固定されることができる方法です役立ちます -

カスタムタイトルビュークラスでこのコードを追加します -

override var intrinsicContentSize: CGSize { 
    return UILayoutFittingExpandedSize 
} 

とカスタムタイトルビューは、正しい位置に表示されます。

+0

それは私のために働く。しかし、私は左/右のバーのボタン項目だけを持っている場合、タイトルビューは絶対的な中心の水平に表示されません。 – Lumialxk

1

を使用すると、タイトルビューにカスタムビューを追加するiOS用の新しいナビゲーションバーに問題があります。したがって、「prefertsLargeTitles」を追加するだけで、いいえ&「largeTitleDisplayMode」はナビゲーションバーのカスタムを実装する前にDisplayModeNeverになります。

ここに私のコード:

if (@available(iOS 11.0, *)) { 
    [[self navigationController] navigationBar].prefersLargeTitles = NO; 
    [[self navigationController] navigationItem].largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeNever; 
    } 
    // Add contraints to titleView 
    NSLayoutConstraint *centerPrompt= [NSLayoutConstraint constraintWithItem:midPromptLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:midView attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0]; 
    NSLayoutConstraint *topPrompt= [NSLayoutConstraint constraintWithItem:midPromptLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:midView attribute:NSLayoutAttributeTop multiplier:1.0 constant:10]; 
    NSLayoutConstraint *centerTitle= [NSLayoutConstraint constraintWithItem:midTitleLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:midView attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0]; 
    NSLayoutConstraint *topTitle= [NSLayoutConstraint constraintWithItem:midTitleLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:midPromptLabel attribute:NSLayoutAttributeTop multiplier:1.0 constant:10]; 

    [midView addConstraints:@[centerPrompt,topPrompt,centerTitle,topTitle]]; 

ホープあなた^ _ ^ここ

+0

回答ありがとうございます私のために働かなかった。しかし私は何かを試して、それは働いた。 –

+0

@PrateekVarshney多分あなたが試したことを分かち合いましたか? –

+0

はい私は答えとしてそれを追加しました –