简描述UIInterfaceOrientation至UIInterfaceOrientationLandscapeRight(或UIInterfaceOrientationLandscapeLeft),以及在文档中所建议的旋转设置的设定,但我在我的根视图控制器使用的代码稍微不同的块(以相同的端部) :
- (void)loadView
{
UIView *primaryView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
primaryView.backgroundColor = [UIColor clearColor];
// Start in landscape orientation, and stay that way
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeRight)
{
CGAffineTransform transform = primaryView.transform;
// Use the status bar frame to determine the center point of the window's content area.
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
CGRect bounds = CGRectMake(0, 0, statusBarFrame.size.height, statusBarFrame.origin.x);
CGPoint center = CGPointMake(60.0, bounds.size.height/2.0);
// Set the center point of the view to the center point of the window's content area.
primaryView.center = center;
// Rotate the view 90 degrees around its new center point.
transform = CGAffineTransformRotate(transform, (M_PI/2.0));
primaryView.transform = transform;
}
self.view = primaryView;
[primaryView release];
}
除此之外,我在根视图控制器中实现的以下委托方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}
最后,我遇到与模拟器不会自动旋转正确怪异的毛刺,所以我需要实现我的UIApplicationDelegate以下的委托方法:
- (void)application:(UIApplication *)application willChangeStatusBarOrientation:(UIInterfaceOrientation)newStatusBarOrientation duration:(NSTimeInterval)duration;
{
// This prevents the view from autorotating to portrait in the simulator
if ((newStatusBarOrientation == UIInterfaceOrientationPortrait) || (newStatusBarOrientation == UIInterfaceOrientationPortraitUpsideDown))
[application setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
}
毕竟,我的应用程序能够在横向启动(右键)并保持在2.0固件和模拟器下的方向。
一种愚蠢的问题,但是在IB查看正确的大小? – 2009-02-08 14:10:39
是的,大小是正确的。 – 2009-02-08 16:44:22