有没有简单的方法来手动设置界面的方向?我需要将界面设置为纵向,即使在加载过程中设备方向可能是横向的。有点想远离CGAffineTransforms。
答案 0 :(得分:16)
我知道一种对我有用的方法(并且有点像黑客,可以在改变你想要的方向之前显示一个方向)是:
- (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];
}
}
答案 1 :(得分:2)
重写此操作以控制方向,直到加载...
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
答案 2 :(得分:2)
首先,将您的应用和视图设置为仅支持肖像,然后使用从我的重构库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
在框架完成之前被取消的视图将不会显示。