2017-10-05 4 views
5

맞춤 탐색 제목보기를 설정하는 iOS 앱이 있습니다.iOS 11 탐색 제목 표시 위치가 잘못되었습니다.

iOS 10까지 제대로 작동했지만 iOS 11에서는 탐색 제목보기가 잘못 배치되었습니다. 다음 The title view looks fine

는 아이폰 OS (11)의 스크린 샷 - - 당신이 볼 수 있듯이

The title view is shifted down

여기

는 아이폰 OS (10)의 스크린 샷이다 스크린 샷은 iOS 10에서 코드를 실행하면 제목보기가 정상적으로 나타납니다. 그러나 iOS 11의 동일한 코드는 제목보기를 일부 픽셀만큼 아래로 이동시키고 잘라냅니다.

이 내가 제목보기를 설정하고 어떻게 - 나는 많은 것들을 시도하고 많은 솔루션을 검색하지만 아무것도 작동하지

navigationItem.titleView = MY_CUSTOM_TITLE_VIEW

.

+0

가능한 [iOS 11 navigationItem.titleView 너비 설정 없음] (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

예 답변으로 추가했습니다 –

관련 문제