带有搜索栏动画故障的大标题

时间:2018-07-12 13:00:39

标签: ios swift xcode

使用以下方法从视图控制器返回时:

navigationItem.largeTitleDisplayMode = .never

使用以下命令查看控制器

navigationController?.navigationBar.prefersLargeTitles = true
navigationItem.largeTitleDisplayMode = .always

在viewDidLoad中,导航栏上出现一个奇怪的动画故障-出现白色条纹

仅当可见searchBar时出现

animation recording

我该如何解决?

3 个答案:

答案 0 :(得分:1)

我在外观转换中发现了问题,导航栏和搜索栏之间有一些空白。他们有独立的动画。 Here is it. 因此,您可以使用transitionCoordinator在“ viewWillAppear”方法中为他们抛出过渡添加通用背景。 That its view.

已编辑:此刻,当您从搜索表过渡到导航时,强文本添加了逻辑。 (searchController.hidesNavigationBarDuringPresentation = true)

override func viewWillAppear(_ animated: Bool) {
    let navigationBack = UIView()
    if navigationItem.searchController?.isActive == false {
        navigationBack.frame = self.navigationController?.navigationBar.frame ?? CGRect.zero
    }
    navigationBack.backgroundColor = navigationController?.navigationBar.barTintColor
    let containerView = transitionCoordinator?.containerView

    transitionCoordinator?.animateAlongsideTransition(in: containerView, animation: { (context) in
        containerView?.addSubview(navigationBack)
        navigationBack.frame.size.height += self.navigationItem.searchController?.searchBar.frame.height ?? 0
    }, completion: { (context) in
        navigationBack.removeFromSuperview()
    })

    super.viewWillAppear(animated)
}

答案 1 :(得分:1)

将导航控制器视图的背景色设置为与导航栏相同的颜色似乎可以解决我的问题。

navigationController?.view.backgroundColor = navigationController?.navigationBar.barTintColor

答案 2 :(得分:0)

有用的是将其添加到启用了largeTitles的viewController中:

function displaydate_tomorrow(){  
    $i = date('l', strtotime('+1 day')) == 'Sunday' ? 2 : 1;        

    return date_i18n('l, j. F', strtotime("+$i day")); 
}  

,并且在viewController中禁用了largeTitles:

override func viewWillAppear(_ animated: Bool) {
    let navigationBack = UIView()
    navigationBack.frame = (self.navigationController?.navigationBar.frame)!
    navigationBack.frame.size.height = 44
    navigationBack.backgroundColor = navigationController?.navigationBar.barTintColor
    let containerView = transitionCoordinator?.containerView

    transitionCoordinator?.animateAlongsideTransition(in: containerView, animation: { (context) in
        containerView?.addSubview(navigationBack)
        navigationBack.frame.size.height = (self.navigationItem.searchController?.searchBar.frame.height)! + (self.navigationController?.navigationBar.frame.height)!
    }, completion: { (context) in
        navigationBack.removeFromSuperview()
    })

    super.viewWillAppear(animated)
}