本文介绍了UISearchBar宽度在横向错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当您在横向模式中开始时,我的搜索栏被拉得太远了。如果然后旋转到纵向模式,它仍然稍微过宽。然而,它的罚款,如果你开始在人像模式,也如果你然后旋转到风景。这是我的代码。
My search bar is stretched slightly too far right when you start in landscape mode. It is still slightly too wide if you then rotate to portrait mode. However, its fine if you start in portrait mode and also if you then rotate it to landscape. Here is my code.
sBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
[sBar sizeToFit];
sBar.delegate = self;
sBar.autoresizingMask = UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleBottomMargin;
[self.view addSubview:sBar];
推荐答案
答案是将搜索栏添加到视图
The answer was to add the search bar to the view before running the rest of the code.
UISearchBar * tempSBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
self.sBar = tempSBar;
[tempSBar release];
[self.view addSubview:sBar];
[sBar sizeToFit];
sBar.delegate = self;
sBar.autoresizingMask = UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleBottomMargin;
这篇关于UISearchBar宽度在横向错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!