簡描述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