SearchBar旋转问题
我对图像感到抱歉,但我不知道更好的方法来解释我的问题。 这是我启动应用程序时的视图,一切都很好。 这是当我旋转手机时,搜索栏顶部现在位于导航栏下方一点。 我开始搜索并取消它。 现在搜索栏不再被导航栏覆盖,但导航栏的高度变小了。 当我回到垂直视图时,导航栏仍然很小,并且下面有一个黑洞。 我找不到为什么会发生这种情况,有什么帮助吗?
这是我创建和添加搜索栏的代码:
- (void) loadView
{
[super loadView];
sBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0,320,45)];
sBar.delegate = self;
sBar.placeholder = @"Search";
self.tableView.tableHeaderView = sBar;
UISearchDisplayController *searchDC = [[UISearchDisplayController alloc] initWithSearchBar:sBar contentsController:self];
self.searchDisplayController = searchDC;
searchDC.delegate = self;
searchDC.searchResultsDataSource = self;
searchDC.searchResultsDelegate = self;
[sBar release];
[searchDC release];
}
我没有专门针对导航或搜索栏更改旋转方法中的任何内容。
I am sorry for images but I don't know better way to explain my problem.
This is view when I start application, all is fine.
This is when I rotate phone, search bar top part is now a little bit under navigation bar.
I start search and cancel it.
Now search bar is not covered with navigation bar, but navigation bar is smaller by height.
And when I go bac to vertical view, navigation bar is still small and I have a black hole under it.
And I can't find why this is happening, any help?
This is the code how I create and add search bar:
- (void) loadView
{
[super loadView];
sBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0,320,45)];
sBar.delegate = self;
sBar.placeholder = @"Search";
self.tableView.tableHeaderView = sBar;
UISearchDisplayController *searchDC = [[UISearchDisplayController alloc] initWithSearchBar:sBar contentsController:self];
self.searchDisplayController = searchDC;
searchDC.delegate = self;
searchDC.searchResultsDataSource = self;
searchDC.searchResultsDelegate = self;
[sBar release];
[searchDC release];
}
I didn't change anything in rotation methods specifically for navigation or search bar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
验证您的所有视图框架:
如果它们不正确,请设置正确的框架。
Verify all your views frames in:
And if they are not ok set the correct frame.
最简单的解决方案是将
UISearchBar
添加到UITableView
标头。在这种情况下,所有员工都将被开箱即用地处理。在视图之间切换和旋转时,设置框架可能会导致 UISearchBar 宽度出现问题。我在基于选项卡的应用程序中遇到了这个问题。是的,测试用例并不那么容易重现,但它仍然是一个错误。
The simpliest solution is to add
UISearchBar
toUITableView
header. In this case all staff will be handled out of the box.Setting frame can cause problems with UISearchBar width while switching between views and rotating. I experienced this issue in tab based app. Yeah, the test case is not so easy to reproduce, but stil it's a bug.