【发布时间】:2012-02-23 04:52:24
【问题描述】:
目前正在创建在登录屏幕后显示 Tabbar 的 iPad 应用程序。到目前为止,成功地能够显示标签栏及其相关视图,唯一的问题是我的标签栏没有以横向模式出现。
我只希望我的应用程序是横向的。
请建议我如何将纵向标签栏旋转到横向标签栏。
【问题讨论】:
目前正在创建在登录屏幕后显示 Tabbar 的 iPad 应用程序。到目前为止,成功地能够显示标签栏及其相关视图,唯一的问题是我的标签栏没有以横向模式出现。
我只希望我的应用程序是横向的。
请建议我如何将纵向标签栏旋转到横向标签栏。
【问题讨论】:
试试这段代码:- For(Rotate one UIViewController in UITabBar) In viewWillAppear and use CGAffineTransform
- (void)viewWillAppear:(BOOL)animated; {
//-- Adjust the status bar
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
//-- Rotate the view
CGAffineTransform toLandscape = CGAffineTransformMakeRotation(degreesToRadian(90));
toLandscape = CGAffineTransformTranslate(toLandscape, +90.0, +90.0 );
[self.view setTransform:toLandscape];
}
更改所有项目:- 复制并粘贴到所有 ViewController 中
1)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
2) Change in Info.Plist
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
</array>
【讨论】:
在您的所有 viewControlle.m 文件中使用此方法
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
【讨论】:
除了在所有相关的视图控制器中实现 shouldAutorotateToInterfaceOrientation: 之外,请确保您的 myProjectName-info.plist 文件指定您选择的支持的界面方向:
您也可以通过在项目导航器中选择您的项目(视图 > 导航器 > 显示项目导航器)来设置此设置,选择您的目标,然后选择“摘要”选项卡,然后按所需的方向按钮:
【讨论】: