【发布时间】:2011-08-31 21:57:49
【问题描述】:
有没有简单的方法来手动设置界面的方向?即使在加载过程中设备方向可能是横向的,我也需要将界面设置为纵向。有点想远离 CGAffineTransforms。
【问题讨论】:
有没有简单的方法来手动设置界面的方向?即使在加载过程中设备方向可能是横向的,我也需要将界面设置为纵向。有点想远离 CGAffineTransforms。
【问题讨论】:
我知道的一种对我有用的方法(有点小技巧,可以在更改为您想要的方向之前显示一个方向)是:
- (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];
}
}
【讨论】:
首先,将您的应用和视图设置为仅支持纵向,然后使用从我的重构库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
在帧完成之前关闭的视图将不会显示。
【讨论】:
覆盖它以控制方向直到加载...
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
【讨论】: