在横向模式下,搜索栏和表格视图不适合屏幕

发布于 2024-12-02 14:32:25 字数 850 浏览 0 评论 0原文

我正在使用以下代码以编程方式创建搜索栏和表格视图,

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

enter image description here
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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

您已经告诉视图调整大小,但没有告诉您创建的搜索栏调整大小,请尝试以下操作:

searchbar.autorezingMask = UIViewAutoresizingFlexibleWidth;

对表视图执行相同的操作。

看看这是否会给您带来您正在寻找的结果。如果这不起作用,您可以随时在旋转后调整搜索栏和表格视图的框架大小。

you have told the view to resize but you haven't told the search bar you created to resize try something like:

searchbar.autorezingMask = UIViewAutoresizingFlexibleWidth;

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.

jJeQQOZ5 2024-12-09 14:32:25

尝试在 ViewWillAppear 方法中调用此 autoresizingMask 。

Try calling this autoresizingMask in ViewWillAppear method.

碍人泪离人颜 2024-12-09 14:32:25

如果您指定任何对象的框架...您必须在其旋转时提供新框架。
在下面的方法中基于toInterfaceOrientation给出一个新的框架。

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

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.

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文