gpt4 book ai didi

iphone - 如何在 iOS 上旋转自定义启动画面?

转载 作者:可可西里 更新时间:2023-11-01 04:28:17 25 4
gpt4 key购买 nike

我的启动画面正常,但我的应用程序在横向模式下运行,启动画面以默认的纵向模式显示。

如何启动应用程序,以便启动画面像我的应用程序一样在横屏模式之间旋转?

我正在使用以下代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight)
return YES;
else {
return NO; }
}

和启动画面

-(void)displayScreen { 
UIViewController *displayViewController=[[UIViewController alloc] init];
displayViewController.view = displaySplashScreen;
[self presentModalViewController:displayViewController animated:NO];
[self performSelector:@selector(removeScreen) withObject:nil afterDelay:3.0];
}
-(void)removeScreen
{ [[self modalViewController] dismissModalViewControllerAnimated:YES];
}

但是我怎样才能把旋转放在显示屏幕内呢?

最佳答案

啊哈。如果你想显示你自己的启动画面,你应该为此创建一个特殊的 View Controller ,你已经这样做了。我认为你可以简化自动旋转查询代码:

- (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]);
}

有点乱,我自己对更简单的解决方案很感兴趣。

关于iphone - 如何在 iOS 上旋转自定义启动画面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4373985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com