如何将屏幕旋转到横向显示?
您能提供简单的代码建议吗?
您能提供简单的代码建议吗?
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
为了实现自动旋转,请按照以下步骤操作:
如果您的应用程序具有 uiTabBarController,则必须对其进行子类化,并向其中添加该方法。像这样:
@interface MyTabBarController : UITabBarController {
}
@end
#import "MyTabBarController.h"
@implementation MyTabBarController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
@end
只需在您的视图控制器文件中实现此功能,就完成了。
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation
{
return YES;
}
UITabBarController
shouldAutorotateToInterfaceOrientation:
让我感到非常沮丧,因为它不是我出于任何原因而进行子类化的类(即,对于我的应用程序来说,默认功能很好)。@interface UITabBarController (WithRotation)
@end
@implementation UITabBarController (WithRotation)
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation {
return YES;
}
@end
p.s. 如果您只想支持某些屏幕方向,请测试接口方向并仅在适当的方向返回YES。
p.p.s. 什么是info.plist中的Supported interface orientations
?唯一重要的事情似乎是从shouldAutorotateToInterfaceOrientation:
返回的内容。