我有一个透明的UINavigationBar
设置为 appearance
, 不涉及子类。
我想添加一个将“充当”UINavigationBar
的 View 的背景,此 View 还有一个展开/折叠自定义搜索栏(不是 UISearchBar
的子类)。我将此 View 称为 OverlayView。
之所以这样,主要是因为背景颜色要动态变化。
我已将 OverlayView 添加为 UINavigationBar
的 subview .它显示正确并且它做我需要的一切。但是当我点击搜索文本字段时,它不会接受点击,即我无法在搜索字段中输入任何内容。
我有userInteractionEnabled
设置为 YES
在我的 OverlayView 和 UINavigationBar
上.
我应该在别处添加我的 OverlayView 吗?我怎样才能识别该 View 上的点击?
最佳答案
试试这个可能对你有帮助。
UISearchBar *searchBar = [UISearchBar new];
searchBar.showsCancelButton = YES;
[searchBar sizeToFit];
[searchBar becomeFirstResponder];
UIView * OverlayView = [[UIView alloc]initWithFrame:searchBar.bounds];
[OverlayView addSubview:searchBar];
self.navigationItem.titleView = OverlayView;
关于ios - 向 UINavigationBar 添加覆盖 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32381691/