有没有简单的方法手动设置界面方向? 在加载时,我需要将界面设置为纵向,即使设备方向可能为横向。 希望能避免使用CGAffineTransforms。
我知道的一种方法(有点hack,可以在更改为所需方向之前显示一个方向)是:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UIApplication* application = [UIApplication sharedApplication];
if (application.statusBarOrientation != UIInterfaceOrientationPortrait)
{
UIViewController *c = [[UIViewController alloc]init];
[self presentModalViewController:c animated:NO];
[self dismissModalViewControllerAnimated:NO];
[c release];
}
}
在加载之前,重写此方法以控制方向...
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
首先,将您的应用程序和视图设置为仅支持纵向模式,然后使用我从我的重构库 es_ios_utils 中获取的此类别方法:
@interface UIViewController(ESUtils)
// Forces without using a private api.
-(void)forcePortrait;
@end
@implementation UIViewController(ESUtils)
-(void)forcePortrait
{
//force portrait orientation without private methods.
UIViewController *c = [[UIViewController alloc] init];
[self presentModalViewController:c animated:NO];
[self dismissModalViewControllerAnimated:NO];
[c release];
}
@end
在帧完成之前被关闭的视图将不会显示。