我正在导航栏中处理非常简单的动画:我有导航栏,右侧有2个按钮。在搜索图标点击我动画导航栏,以便它隐藏按钮和搜索图标,并显示搜索栏。在取消按钮点击它相反。简单
lazy var searchBar:UISearchBar = UISearchBar()
override func viewDidLoad() {
super.viewDidLoad()
self.automaticallyAdjustsScrollViewInsets = false
searchBar.delegate = self
searchBar.backgroundColor = UIColor.darkGray
searchBar.tintColor = UIColor(red: 140/255, green: 195/255, blue: 65/255, alpha: 1.0)
}
点击搜索按钮时,搜索栏会添加到导航栏中,但左侧和右侧略微剪掉。
@IBAction func subjectTapped(_ sender: Any) {
self.navigationItem.setRightBarButtonItems(nil, animated: true)
self.navigationItem.setLeftBarButtonItems(nil,animated: true)
self.navigationItem.titleView = nil
searchBar.placeholder = "I am looking for ..."
searchBar.alpha = 0
self.navigationItem.titleView = searchBar
UIView.animate(withDuration: 0.5, animations: {
self.searchBar.alpha = 1
}, completion: { finished in
self.searchBar.becomeFirstResponder()
})
}
请告诉我我做错了什么,并解决了这个问题