在横向模式下,搜索栏和表格视图不适合屏幕
我正在使用以下代码以编程方式创建搜索栏和表格视图,
UISearchBar* searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0,320,40)];
searchBar.delegate = self;
[self.view addSubview:searchBar];
UITableView* tblView = [[UITableView alloc]initWithFrame:CGRectMake(0, 41, 320, 400)];
tblView.delegate = self;
tblView.dataSource = self;
[self.view addSubview:tblView];
现在我在以下方法中设置了返回值 yes 来旋转屏幕设备方向
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
,并且我在 loadView
中使用了以下代码,
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
以下是我的输出
但搜索栏和表格视图仍然不适合横向模式下的屏幕,我该怎么办,任何人都可以帮助我,,提前谢谢
i am creating the search bar and table view programatically using the following code
UISearchBar* searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0,320,40)];
searchBar.delegate = self;
[self.view addSubview:searchBar];
UITableView* tblView = [[UITableView alloc]initWithFrame:CGRectMake(0, 41, 320, 400)];
tblView.delegate = self;
tblView.dataSource = self;
[self.view addSubview:tblView];
now i made the return value yes in the following method to to rotate the screen wrt device orientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
and i used following code in loadView
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
following is my output
but still search bar and table views are not fitting to the screen in landscape mode, what should i do can any one help me,,thanx in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您已经告诉视图调整大小,但没有告诉您创建的搜索栏调整大小,请尝试以下操作:
对表视图执行相同的操作。
看看这是否会给您带来您正在寻找的结果。如果这不起作用,您可以随时在旋转后调整搜索栏和表格视图的框架大小。
you have told the view to resize but you haven't told the search bar you created to resize try something like:
do the same for the table view.
see if that gives you the result you are looking for. IF that doesn't work you can always resize the frame of the search bar and table view after rotation.
尝试在 ViewWillAppear 方法中调用此 autoresizingMask 。
Try calling this autoresizingMask in ViewWillAppear method.
如果您指定任何对象的框架...您必须在其旋转时提供新框架。
在下面的方法中基于toInterfaceOrientation给出一个新的框架。
if you assign frame of any object...you have to provide new frame when it rotates.
Give a new frame in following method based on toInterfaceOrientation.