Friday, 6 September 2013

iOS add image to window in right orientation

iOS add image to window in right orientation

I am trying to add an image view to my application window which consists
of a splitviewcontroller. The reason I am doing this is so that I can fade
it out like a splash screen. The application is for iPad and only works in
the landscape mode. The launch image is the same as the splash image so it
is a seamless transition between the two, then I can manually fade out the
splash. However I am having trouble adding the splash to the window's
subview in the same orientation as the launch image so that the transition
from the launchimage to the splash is seamless and cannot be noticed. Here
is what I have so far:
- (void)viewDidLoad
{
[super viewDidLoad];
UIWindow *window = [[UIApplication sharedApplication] delegate].window;
UIImageView *splash = [[UIImageView alloc] initWithFrame:[[UIScreen
mainScreen] bounds]];
splash.image = [UIImage imageNamed:@"Default-Landscape~ipad.png"];
[splash rotateToInterfaceOrientation:[[UIApplication
sharedApplication] statusBarOrientation]];
[window addSubview:splash];
}
@interface UIView (Orientation)
- (void)rotateToInterfaceOrientation:(UIInterfaceOrientation)orientation;
@end
@implementation UIView (Orientation)
- (void)rotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
{
CGFloat angle = 0.0;
switch (orientation) {
case UIInterfaceOrientationPortraitUpsideDown:
angle = M_PI;
break;
case UIInterfaceOrientationLandscapeLeft:
angle = - M_PI / 2.0f;
break;
case UIInterfaceOrientationLandscapeRight:
angle = M_PI / 2.0f;
break;
default: // As portrait
angle = 0.0;
break;
}
self.transform = CGAffineTransformMakeRotation(angle);
}
@end

No comments:

Post a Comment