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?
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:
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) foo
{
return YES; // all interface orientations supported
}
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:
- (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);
}
There are two utility functions called, you can stuff these into a separate file:
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]);
}
It’s a bit messy, I’d be interested in simpler solution myself.
@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.
- (UIView *)startupImageWithOrientation:(UIInterfaceOrientation)io{
UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"Default-%@.png", UIInterfaceOrientationName(io)]];
UIView *aView = [[UIImageView alloc] initWithImage:img];
[aView setFrame:[[UIScreen mainScreen] applicationFrame]];
// define the version number label
self.versionNumberLabel_iPadSplashScreen.text = [NSString stringWithFormat:@"Version %@",
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]];
[aView addSubview:self.versionNumberLabel_iPadSplashScreen];
return [aView autorelease];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With