我有一个iOS应用,我正在设置自定义导航标题视图。
直到iOS 10才正常工作,但在iOS 11中导航标题视图放错了位置。
以下是iOS 10的屏幕截图 -
以下是iOS 11的屏幕截图 -
正如您在屏幕截图中看到的那样,当我在iOS 10上运行代码时,标题视图似乎没问题。但是iOS 11上的相同代码会将标题视图向下移动一些像素并且会被切断。
这就是我设置标题视图的方式 -
navigationItem.titleView = MY_CUSTOM_TITLE_VIEW
我尝试了很多东西并寻找了许多解决方案,但没有任何效果。
答案 0 :(得分:15)
以下是如何解决的问题 -
在自定义标题视图类中添加此代码 -
$("#edit-date-debut").datepicker({ dateFormat: 'dd-mm-yy' });
自定义标题视图显示在正确的位置。
答案 1 :(得分:2)
当您在标题视图中添加自定义视图时,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]];
希望能帮到你^ _ ^