如何在 iOS 上旋转自定义启动屏幕?
我的启动屏幕可以正常工作,但我的应用程序可以在横向模式下运行,并且启动屏幕以默认的纵向模式显示。
如何启动应用程序,以便启动屏幕像我的应用程序一样在横向模式之间旋转?
我正在使用以下代码:
- (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];
}
但是如何将旋转放在显示屏内?
My splash screen is working, but my app works on landscape mode, and the splash screen shows in the default portrait mode.
How can I start the app so that the splash screen rotates between landscape modes like my app?
I'm using the following code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight)
return YES;
else {
return NO; }
}
and for the splash screen
-(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];
}
But how can I put the rotate inside the display screen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
啊哈。如果您想显示自己的启动屏幕,您应该为此创建一个特殊的视图控制器,您已经这样做了。我认为您可以简化自动旋转查询代码:
现在您必须考虑不同方向的启动屏幕。您有单独的横向和纵向启动图像吗?如果是,你可以这样做:
有两个实用函数被调用,你可以将它们填充到一个单独的文件中:
这有点混乱,我自己对更简单的解决方案感兴趣。
Aha. If you want to display your own splash screen, you should create a special view controller for that, which you already did. I think you can simplify the autorotation query code:
Now you have to think about the splash screens for different orientations. Do you have a separate splash image for landscape and portrait? If yes, you can do something like this:
There are two utility functions called, you can stuff these into a separate file:
It’s a bit messy, I’d be interested in simpler solution myself.
@zoul - 到目前为止喜欢这个解决方案。但是,如果/当该视图有任何子视图时 - 它们不会显示。有什么想法吗?
更新:
通过向在
-startupImageWithOrientation:
not self.view 中创建的 UIView 添加子视图来修复此问题。@zoul - loving this solution so far. however, if/when that view has any subviews - they don't show up. any ideas?
update:
fixed this issue by adding a subview to the UIView created in
-startupImageWithOrientation:
not self.view.如果您锁定了方向,则 default.png 的分辨率可能会影响您的应用程序方向。
例如,如果使用 1024x768 初始图像,并且初始视图不支持通过方向锁定纵向查看,这可能会导致视觉 UI 对象出现在屏幕外(尤其是在涉及动画时),因为视图会尝试以纵向方式呈现自身即使设备可能处于横向配置。
一般来说,1024x768 图像意味着纵向,而 768x1024 图像意味着横向。
如果这还不够,或者您希望从初始默认图像无缝转到登录屏幕等,那么您可以使用视图控制器“继续”启动画面。
将所有正常的 viewController 加载到窗口中,然后将您的“splash”viewController 放入,然后在您的splashController中使用shouldAutorotateToInterfaceOrientation方法设置正确的图像(在ImageViewController上):
我使用的图像的配置可能不适合您,因此可能需要进行一些实验。
The resolution of your defult.png can effect your apps orientation if you have locked orientations.
For example if a 1024x768 splash image is used and the initial view doesn’t support portrait viewing through orientation locks this can cause visual UI objects to appear off screen (especially when animation is involved) as the view will try and present itself in a portrait configuration even though the device may be in landscape.
Generally, 1024x768 images imply portrait while 768x1024 images imply landscape.
If this isn't enough, or your wanting to seamlessly go from the initial default image into e.g a login screen, then you can use a viewcontroller to 'continue' the splash .
Load all the normal viewControllers into the window, then put your 'splash' viewController in then in your splashController use
shouldAutorotateToInterfaceOrientation
method to set the right image (on an ImageViewController):The configuration of the images i have used may not suit you, so some experimentation might be needed.
请注意,您应该返回 YES 方法
shouldAutorotateToInterfaceOrientation:
note that you should return YES the method
shouldAutorotateToInterfaceOrientation: