Skip to content

Commit

Permalink
Add portrait/landscape/rotation support to loading image
Browse files Browse the repository at this point in the history
  • Loading branch information
msgilligan committed Aug 9, 2010
1 parent ab5b627 commit d3fa039
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion PhoneGapLib/Classes/PhoneGapDelegate.m
Expand Up @@ -3,6 +3,9 @@
#import <UIKit/UIKit.h>
#import "Movie.h"
#import "InvokedUrlCommand.h"
#import <QuartzCore/QuartzCore.h>

#define degreesToRadian(x) (M_PI * x / 180.0)

@implementation PhoneGapDelegate

Expand Down Expand Up @@ -206,8 +209,44 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
* imageView - is the Default loading screen, it stay up until the app and UIWebView (WebKit) has completly loaded.
* You can change this image by swapping out the Default.png file within the resource folder.
*/
UIImage* image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default" ofType:@"png"]];
UIDevice *device = [UIDevice currentDevice];
// NSLog(@"Startup orientation is device = %d, interface = %d", device.orientation, self.viewController.interfaceOrientation);
// It looks like device orientation and interface orientation are not in sync on startup. We either need to bring them into sync
// somehow or do some rotates on the startup images before adding them as subview...
// For now let's try the rotates. Note: device.orientation is always Portrait on the simulator?
NSString *loadingImageResource;
BOOL iPad = NO;
#ifdef UI_USER_INTERFACE_IDIOM
iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
#endif
CGAffineTransform startupImageTransform = CGAffineTransformIdentity;
if (iPad) {
if (device.orientation == UIDeviceOrientationLandscapeRight) {
loadingImageResource = @"Default-Landscape";
startupImageTransform = CGAffineTransformMakeRotation(degreesToRadian(-90));
}
else if (device.orientation == UIDeviceOrientationLandscapeLeft) {
loadingImageResource = @"Default-Landscape";
startupImageTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
}
else if (device.orientation == UIDeviceOrientationPortraitUpsideDown) {
loadingImageResource = @"Default-Portrait";
startupImageTransform = CGAffineTransformMakeRotation(degreesToRadian(180));
}
else {
loadingImageResource = @"Default-Portrait";
}

} else {
loadingImageResource = @"Default";
}
UIImage* image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:loadingImageResource ofType:@"png"]];
imageView = [[UIImageView alloc] initWithImage:image];
if (iPad && !CGAffineTransformIsIdentity(startupImageTransform))
{
imageView.center = CGPointMake (384.0, 512.0);
[imageView setTransform:startupImageTransform];
}
[image release];

imageView.tag = 1;
Expand Down

2 comments on commit d3fa039

@goosefx
Copy link

@goosefx goosefx commented on d3fa039 Nov 9, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I tried this but still if I start my app in landscape on a real iPad - device orientation is always portrait. My problem is that willRotateToInterfaceOrientation is first fired after the image was created inside didFinishLaunchingWithOptions.

@msgilligan
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw some strange behavior similar to what you describe. There may be some more tweaking needed. I haven't looked at this since I originally posted, so you might want to check and see if anyone else has done anything further/better. I'm not going to have time to look at this for awhile. I wanted to post this because I thought it was at least a step in the right direction...

Please sign in to comment.