啊哈。如果您想显示自己的启动屏幕,您应该为此创建一个特殊的视图控制器,您已经这样做了。我认为你可以简化自动旋转查询代码:
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) foo
{
return YES; // all interface orientations supported
}
现在您必须考虑不同方向的启动屏幕。您有单独的横向和纵向启动图像吗?如果是,你可以这样做:
- (UIView*) startupImageWithOrientation: (UIInterfaceOrientation) io
{
UIImage *img = [UIImage imageNamed:[NSString
stringWithFormat:@"Default-%@.png", UIInterfaceOrientationName(io)]];
UIView *view = [[UIImageView alloc] initWithImage:img];
[view setFrame:[[UIScreen mainScreen] applicationFrame]];
return [view autorelease];
}
- (void) loadView
{
self.view = [self startupImageWithOrientation:self.interfaceOrientation];
}
- (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation) io
duration: (NSTimeInterval) duration
{
self.view = [self startupImageWithOrientation:io];
self.view.transform = CGAffineTransformFromUIOrientation(io);
}
有两个实用函数被调用,您可以将它们填充到一个单独的文件中:
NSString *UIInterfaceOrientationName(UIInterfaceOrientation io)
{
return UIInterfaceOrientationIsPortrait(io) ? @"Portrait" : @"Landscape";
}
CGAffineTransform CGAffineTransformFromUIOrientation(UIInterfaceOrientation io)
{
assert(io <= 4);
// unknown, portrait, portrait u/d, landscape L, landscape R
static float angles[] = {0, 0, M_PI, M_PI/2, -M_PI/2};
return CGAffineTransformMakeRotation(angles[io]);
}
这有点混乱,我自己对更简单的解决方案感兴趣。