Rav*_*avi 2 iphone xcode landscape objective-c uiinterfaceorientation
我正在使用以下代码以编程方式创建搜索栏和表视图
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];
Run Code Online (Sandbox Code Playgroud)
现在我在下面的方法中使返回值为yes以旋转设备方向的屏幕
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
Run Code Online (Sandbox Code Playgroud)
我使用下面的代码 loadView
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
Run Code Online (Sandbox Code Playgroud)
以下是我的输出
但仍然搜索栏和表格视图不适合横向模式的屏幕,我应该做什么可以任何人帮助我,, thanx提前
你告诉视图调整大小,但你还没有告诉你创建的搜索栏调整大小尝试类似:
searchbar.autorezingMask = UIViewAutoresizingFlexibleWidth;
Run Code Online (Sandbox Code Playgroud)
对表视图执行相同的操作.
看看是否能为您提供所需的结果.如果不起作用,您可以在旋转后始终调整搜索栏和表格视图的框架.