Phonegap-ipad app - 根据Orientation调整启动图像

时间:2011-05-20 06:58:29

标签: objective-c ios ipad cordova

我正在尝试使用phonegap探索ipad dev。我现在的问题是,

我有不同方向的四种不同的发布图像。启动应用程序后,会显示正确的启动图像。在此之后,phonegap尝试使用 default.png 加载图像视图并显示它直到webview完全加载。问题出在这里..图像视图基于当前方向自动旋转。因此,如果当前方向是LandscapeLeft,imageview会在显示之前尝试旋转default.png这不是我想要的,这就是为什么我有不同的启动图像。所以实际上,你将有一个landscapeleft.png,然后自动旋转在我看到webview之前的default.png。

所以我尝试改变这样的phonegapdelegate(在 applicationDidFinishLaunching 中)

UIImage* image=nil;
if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight ){
    NSLog(@"In default5");
    image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default5" ofType:@"png"]];
}
if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft ){
    NSLog(@"In default6");
    image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default6" ofType:@"png"]];
}

if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown ){
    NSLog(@"In default7");
    image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default7" ofType:@"png"]];
}
imageView = [[UIImageView alloc] initWithImage:image];
[image release];

它不起作用,在调试时我发现statusbarorientation总是肖像。这可能是因为phonegap尝试将肖像设置为同一 applicationDidFinishLaunching 方法中的状态栏方向(在加载此图像视图之前)。

有人可以告诉我如何使用正确的图像加载图像视图吗?

2 个答案:

答案 0 :(得分:2)

使用这些名称:

  • 默认-LandscapeLeft-ipad.Png
  • 默认-LandscapeRight-ipad.Png
  • 默认画像-ipad.Png
  • 默认-PortraitUpsideDown-ipad.Png

更多:http://www.weston-fl.com/blog/?p=840

答案 1 :(得分:0)

applicationDidFinishLaunching 对于应用程序从操作系统接收方向更改通知来说为时尚早。因此,您无法在此确定方向。

因此,最好的解决方案是在能够确定当前方向的生命周期阶段进行。在我的例子中, webViewDidStartLoading