0

if I set a search bar to the navigation titleView, like

navigationController?.navigationBar.topItem?.titleView = self.searchBar

, but I set it's frame by using autolayout like:

self.searchBar.snp_makeConstraints { make in
        make.left.equalTo(leftSpace)
        make.right.equalTo(-leftSpace)
        make.top.equalTo(10)
        make.height.equalTo(44)
}

, and then it will cause broken if I push to another view controller.

And if I set it's frame by using this way:

self.searchBar.frame = CGRectMake(leftSpace, 0, screenSize.width - 2 * leftSpace, 44)

it runs well...

Anyone can tell me why? Thx...

pedrouan
  • 12,762
  • 3
  • 58
  • 74
dyljqq
  • 41
  • 3

1 Answers1

0

TitleView's layout is managed by navigation controller. The constraints you've added to your view will be ignored when added to titleView. If you want to fully customized the navigation bar, I suggest to create your own view.

Xchord
  • 678
  • 1
  • 5
  • 20
  • Thx first. But I can see the title view is correctly show in the navigation bar, and if I push to another view controller, then broken. – dyljqq Sep 22 '16 at 03:06